简体   繁体   English

ASP / MVC-在JavaScript代码中切换局部视图

[英]ASP/MVC - Switch a partial view in javascript code

I have table on my view page. 我的视图页面上有桌子。 One of the cells has an ID (say "x"). 单元格之一具有ID(例如“ x”)。 When a certain button is clicked a JS function is called, and the purpose is to dynamically change the partial view contained inside that cell using the code: 单击某个按钮时,将调用JS函数,其目的是使用代码动态更改该单元格内包含的局部视图:

$("#X")[0].innerHTML = @Html.Partial("PartialViewName");

It works perfectly on firefox, but not in IE8. 它可以在Firefox上完美运行,但在IE8中则不能。 Also, FIY,the partial view is an AJAX form. 同样,FIY,局部视图是AJAX形式。

You can load the partial view by ajax like this using Jquery load , 您可以使用Jquery load这样通过ajax加载部分视图,

$("#X").load(@Url.Action("action","controller"));

and in the controller you have to return the partial view like this, 在控制器中,您必须像这样返回部分视图,

public ActionResult Action(){  
    return PartialView('PartialViewName')
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM