我在这里从这个页面做教程,我主要是在复制
http://ricardocovo.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/
它不工作,我不知道为什么。根本没有反应。
这是我的编辑方法
public ActionResult Edit(int id)
{
ViewBag.Categories = CategoriesSelectList();
return PartialView(proxy.GetProduct(id));
}
这是我的编辑视图(部分视图)。但我看不出与正常视图有什么不同。
@model Shop.Data.ProductType
<h2>Edit</h2>
@using (Ajax.BeginForm("Edit", "Shop", null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "updateSuccess"
}, new { id = "updateShopForm" }))
{
@Html.ValidationSummary(true)
<div id="update-message" class="error invisible"></div>
<fieldset>
<legend>Products</legend>
@Html.HiddenFor(model => model.CategoryID)
@Html.Label("Nazwa")
<div class="editor-label">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<br />
<br />
@Html.Label("Kategoria")
<div class="editor-label">
@Html.DropDownList("CategoryID", new SelectList(ViewBag.Categories, "value", "text"))
@Html.ValidationMessageFor(model => model.CategoryID)
</div>
</fieldset>
}
这是教程中的这个长java
<div id="updateDialog" title="Update Product">
</div>
<script type="text/javascript">
var linkObj;
$(function () {
$(".edit-link").button();
$('#updateDialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
modal: true,
buttons: {
"Update": function () {
$("#update-message").html(''); //make sure there is nothing on the message before we continue
$("#updateShopForm").submit();
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$(".edit-link").click(function () {
//change the title of the dialgo
linkObj = $(this);
var dialogDiv = $('#updateDialog');
var viewUrl = linkObj.attr('href');
$.get(viewUrl, function (data) {
dialogDiv.html(data);
//validation
var $form = $("#updateShopForm");
// Unbind existing validation
$form.unbind();
$form.data("validator", null);
// Check document for changes
$.validator.unobtrusive.parse(document);
// Re add validation with changes
$form.validate($form.data("unobtrusiveValidation").options);
//open dialog
dialogDiv.dialog('open');
});
return false;
});
});
function updateSuccess() {
if ($("#update-message").html() == "True") {
//we update the table's info
var parent = linkObj.closest("tr");
parent.find(".carName").html($("#Name").val());
parent.find(".carDescription").html($("#Description").val());
//now we can close the dialog
$('#updateDialog').dialog('close');
//twitter type notification
$('#commonMessage').html("Update Complete");
$('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
}
else {
$("#update-message").show();
}
}
</script>
这是我的编辑链接
@Html.ActionLink("Edytuj", "Edit", new { id = m.ID }, new { @class = "edit-link" })
找不到任何区别。