简体   繁体   English

以前的所有建议都无法将我的部分视图加载到 <div> 在按钮上单击

[英]All previous suggestions fail to load my partial view into a <div> on button click

All suggestions on this site regarding loading a Partial View in a div on a button click fail for me. 该网站上有关在按钮上单击单击以加载div中的部分视图的所有建议对我来说都是失败的。 They either do nothing or return an error. 他们要么不执行任何操作,要么返回错误。 @Html.Action works within a div but no JavaScript/JQuery/Ajax solution works when a button is clicked @Html.Action在div中有效,但是单击按钮时没有JavaScript / JQuery / Ajax解决方案有效

@Html.Action works within the div but not with javascript @Url.Action doesn't work. @Html.Action在div中有效,但在javascript中不起作用@Url.Action不起作用。 Often gives an error that the string isn't properly terminated @Url.Content is no better than @Url.Action $("#divname").load() returns an error that the object doesn't support "load" 通常会给出错误消息,指出字符串未正确终止@Url.Content并不比@Url.Action$("#divname").load()返回错误,表明对象不支持“ load”

Button: 按键:

<a onclick="Rabbit01()" href="#">Try This</a>

JavaScript 1: JavaScript 1:

function Rabbit01() {
    var wannabe = document.getElementById("whollyinsane");
    var url = '@Url.Action("QuestionLists")';
    var key = 1;
    wannabe.load(url, { id: key }); 
} 

JavaScript 2: JavaScript 2:

function Rabbit01() {
     var url = '@Url.Action("QuestionLists")';
     var key = 1;
     $("#wannabe").load(url, { id: key }); // returns error regarding "load"
}

I expect the controller to respond to the @Url.Action (this works if I put @Html.Action in a di>) and for the resulting partial view to load in the "wannabe" div when the "Try This" button is clicked. 我希望控制器响应@Url.Action (如果我将@Html.Action放在di>中,则可以工作),并且当单击“ Try This”按钮时,将导致的部分视图加载到“ wannabe” div中。

        function Rabbit01() {
            $("#divId").load('@(Url.Action("PartialViewLoadMethod","PartialViewControler"))', function(){});
        }  

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

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