0
這使我瘋狂。我在解決此問題方面遇到問題。該對話框打開,但partialview未加載。我在這裏嘗試過很多例子,但無濟於事。這是迄今爲止我所擁有的。使用JQuery來填充一個MVC4 partialview的模態彈出框
我_layout.cshtml文件有以下幾點:
<div id="modal-content" name="modal-content"></div>
在我site.js我有以下幾點:
$('#modal-content').dialog({
autoOpen: false,
position: { my: 'center', at: 'top+350', of: window },
width: 'auto',
height: 'auto',
fluid: true,
modal: true,
resizable: false,
title: 'Create Guestbook Post',
open: function(event, ui) {
$(this).load('@Url.Action("_Create")');
},
});
$('#buttonCreateGuestbookPost').click(function() {
$('#modal-content').dialog('open');
});
在partialview(_Create.cshtml)我有以下幾點:
@model MPP.Database.Guestbook
@using (Html.BeginForm())
{
<div class="row">
<h2>Create Account</h2>
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<p>
@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label float-left" })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger float-right" })
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
</p>
<p>
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label float-left" })
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control float-right" } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</p>
<p>
@Html.LabelFor(model => model.EmailAddress, htmlAttributes: new { @class = "control-label float-left" })
@Html.EditorFor(model => model.EmailAddress, new { htmlAttributes = new { @class = "form-control float-right" } })
@Html.ValidationMessageFor(model => model.EmailAddress, "", new { @class = "text-danger" })
</p>
<p>
@Html.LabelFor(model => model.Body, htmlAttributes: new { @class = "control-label float-left" })
@Html.EditorFor(model => model.Body, new { htmlAttributes = new { @class = "form-control float-right" } })
@Html.ValidationMessageFor(model => model.Body, "", new { @class = "text-danger" })
</p>
<p>
<input type="submit" id="buttonCreateGuestbook" name="buttonCreateGuestbook" class="btn btn-primary" value="Create" />
</p>
}
</div>
}
在我希望彈出窗口顯示的視圖中,我有以下按鈕:
<a href="javascript:void(0);" class="btn btn-xs btn-success" id="buttonCreateGuestbookPost" style="margin-bottom:3px;">Post to Guestbook</a>
當guestbook頁面加載時,所有組件加載正常(按鈕打開對話框,模式內容DIV,javascript打開/加載對話框等)。問題是,單擊按鈕時,模式對話框打開,但partialview未加載。
任何幫助將不勝感激。謝謝。
敬畏,堅果。看到的例子,jQuery代碼駐留在視圖中。我通過將它移動到一個外部文件而使自己超出了自己。這就是爲什麼,我有時需要第二雙眼睛。謝謝。 –