[英]How to load a modal in a partial view ?
I'm having a problem to load a modal in a partial view, 我在部分视图中加载模态时遇到问题,
$(".create").click(function () {
debugger;
$("#modalTipoPedido").load("ControllerNamePartialView/ActionNamePartialView", function () {
$("#modalTipoPedido").modal();
})
});
When I activate this function, in the method load is added the name of the Controller of the view that my partial view is in, then i got a Non Found Error like this: 当我激活此功能时,在方法负载中添加了我的局部视图所在的视图的Controller的名称,然后出现如下所示的“未找到错误”:
GET http://localhost:2328/ControllerView/ControllerPartialView/ActionNamePartialView 404 (Not Found) GET http:// localhost:2328 / ControllerView / ControllerPartialView / ActionNamePartialView 404(未找到)
How to not add the name of the Controller of the view in load method ? 如何在load方法中不添加视图的Controller名称?
I recommend to use a code similar than this: 我建议使用类似于以下的代码:
<script>
$(function(){
$("#mydialog").dialog({
modal: true,
width: "800px",
autoOpen: false
});
$(".create").on("click", function () {
$("#mydialog").dialog("open");
});
});
</script>
And in your cshtml
file (your View), you can use something like: 在您的cshtml
文件(您的视图)中,您可以使用类似以下内容的代码:
<span class="create">
@Ajax.ActionLink("This is the link",
"ActionNamePartialView",
"ControllerNamePartialView",
new { id = 123 },
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "mydialog"
})
</span>
Now, In your controller
you must have something like: 现在,在您的controller
您必须具有以下内容:
public ActionResult ActionNamePartialView()
{
var model = //Code to get your model;
return PartialView(model);
}
And in your Partial View
: 在您的Partial View
:
@model YourProject.YourModel
<p>All the code that you want to display in your modal</p>
Hope works to you 希望对你有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.