混合剃刀和Java Script code为@ Html.Partial() [英] Mixing razor and java script code for @Html.Partial()

查看:137
本文介绍了混合剃刀和Java Script code为@ Html.Partial()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我提供了如何动态地添加一些code到页面中的MVC解决方案。

我在做这样但在这个code中的页面无法认同指数JavaScript变量,因为它不识别该指数javascript变量。

 的$(document)。在('点击','。新增选项',函数(){
  VAR指数= $(div.ques选项),大小()。
  如果(指数小于5){
    $('。mainContainer上')。追加('@ Html.Partial(_选项,指数))
  }
});


解决方案

这将是更好的使用jQuery load()或通过AJAX行动控制器调用,这种方法描述有<一个href=\"http://stackoverflow.com/questions/3651171/asp-net-mvc-rendering-partial-view-with-jquery-ajax\">ASP.NET MVC呈现局部视图使用jQuery阿贾克斯

Can anyone provide me solution for how to dynamically add some code into the page in MVC.

I was doing this way but in this code the page fails to identity index javascript variable , as it is not identifying the index javascript variable.

$(document).on('click', '.add-option', function () {           
  var index = $("div.ques-options").size();
  if (index < 5) {
    $('.MainContainer').append('@Html.Partial("_Options", index)')
  }
});

解决方案

it would be better to use jQuery load() or call by ajax action in the controller, this approach described there ASP.NET MVC rendering partial view with jQuery ajax

这篇关于混合剃刀和Java Script code为@ Html.Partial()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆