asp.net-mvc - 如何在脚本部分调用部分 View

标签 asp.net-mvc

我是 MVC 新手。我有一个按钮,当我单击它时应该转到部分 View 并返回我需要的数据。我不知道我应该如何实现这一点:

主视图:

<script>

if ($("#btnFilter").click(function () {

  @{Html.RenderPartial("partialView"); }

 }));
</script>

部分 View

var dtDrpVals = new selectedDateDrpdnVal();
debugger;
$.ajax({

    dataType: "json",
    type: "POST",
    url: "@Url.Action("controller","Dashbrd")",
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify({ "regionalManager": dtDrpVals.drpValue, "dtFrom": dtDrpVals.fromDate, "dtTo": dtDrpVals.toDate }),
    success: function (result) {
    }
});

最佳答案

在 html 中定义一个 div,您希望局部 View 位于其中,并在 ajax 成功中将对 Controller 的调用结果放入该 div 中,假设您要返回一个局部 View :

$("#The id of the div").html(result);

关于asp.net-mvc - 如何在脚本部分调用部分 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50256116/

相关文章:

.net - 如何在Web网格的列中编写IF条件

asp.net-mvc - 如何使用 ASP.NET MVC 调试查看 Controller 生成的 html?

c# - 根据参数在 Razor 中切换 Case

asp.net-mvc - 缓存无法在客户端上进行 JSON 响应

asp.net-mvc - 使用存储库 + 工作单元模式选择查询

c# - 如何使 DateTime 模型属性成为必需的?

c# - IsPersistent 在 OWIN Cookie 身份验证中的工作原理

asp.net-mvc - 有什么方法可以检测代码中的经典和集成应用程序池?

c# - MVC4+EntityFramework架构

c# - 返回没有内存泄漏的 base64 图像 ASP.NET MVC 3