javascript - 在 div MVC 中加载部分 View

标签 javascript jquery asp.net-mvc

我的 MVC View 上有一个按钮,单击它后,它应该通过调用将对象作为参数的操作在“div”中添加部分 View

我尝试了这样的事情:

$('#buttonId').onclick(function(){

$('#divid').load(@Html.Action("ActionName","ControllerName",new{parameterName = objectToPass}))

});

但它会在页面加载本身加载操作结果/部分 View ,而不是单击按钮

有什么想法吗?

最佳答案

尝试使用

@Url.Action

而不是

@Html.Action

或者你可以使用ajax,例如:

$('#buttonId').click( function() {
    $.ajax({
        type: 'POST',
        url: '@Url.Content("~/ControllerName/ActionName")',
        data: objectToPass,
        success: function (data) {
           $('#divid').innerHTML = data;
        }
    });
}

关于javascript - 在 div MVC 中加载部分 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9788654/

相关文章:

javascript - Jquery Trigger 多次调用函数

javascript - Bootstrap 4 : Modal won't show on my react app

javascript - 在 node.js 中将 SVG 代码转换为 PNG 数据 URI

javascript - 创建全屏背景图片,但仍允许用户向下滚动

c# - 从 MVC Controller 将 HTML 渲染为字符串

jquery - jQuery 的 ThemeRoller 弄乱了 UI

c# - 如何将c#中的列表转换为javascript中的数组并检查数组项

javascript - React-Stripe-Elements 元素未按预期呈现样式

javascript - 在使用 jQuery 扩展 DIV 时将高度设置为自动

jquery动画: change the element's opacity one by one