[英]How to load a modal in a partial view ?
我在部分視圖中加載模態時遇到問題,
$(".create").click(function () {
debugger;
$("#modalTipoPedido").load("ControllerNamePartialView/ActionNamePartialView", function () {
$("#modalTipoPedido").modal();
})
});
當我激活此功能時,在方法負載中添加了我的局部視圖所在的視圖的Controller的名稱,然后出現如下所示的“未找到錯誤”:
GET http:// localhost:2328 / ControllerView / ControllerPartialView / ActionNamePartialView 404(未找到)
如何在load方法中不添加視圖的Controller名稱?
我建議使用類似於以下的代碼:
<script>
$(function(){
$("#mydialog").dialog({
modal: true,
width: "800px",
autoOpen: false
});
$(".create").on("click", function () {
$("#mydialog").dialog("open");
});
});
</script>
在您的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>
現在,在您的controller
您必須具有以下內容:
public ActionResult ActionNamePartialView()
{
var model = //Code to get your model;
return PartialView(model);
}
在您的Partial View
:
@model YourProject.YourModel
<p>All the code that you want to display in your modal</p>
希望對你有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.