【发布时间】:2011-05-15 05:12:16
【问题描述】:
我正在使用更新到最新版本的 Visual Studio 2010 和更新到最新版本的 MVC3 框架。我也在使用 jquery 1.5.1,但这个问题似乎与 jquery 无关。
我有以下主页:
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css" type="text/css" />
<link href="@Url.Content("~/Content/UserMaintainance.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/UserMaintainance.js")" type="text/javascript"></script>
@model TourSystem2.Models.UserMaintainanceViewModel
@{
ViewBag.Title = "UserMaintainance";
}
@Model.Debug
<h2>User Maintainance</h2>
<div id = "EditUser"></div>
<table>
<tr id="1">
<td><button type="button" class = "deleteButton"></button></td>
<td><button type="button" class = "editButton"></button></td>
<td>John </td>
<td>john </td>
<td>A</td>
<td>1234 </td>
<td></td>
//snipped some unrelated form generation of user information showing
<tr id = "0">
<td colspan = "7"><button type = "button" id = "addButton">Add New User</button></td>
</tr>
</table>
在此表单的 java 脚本中,我对 addButton 执行以下操作:
$(function () {
$(':button.editButton, :button#addButton').click(function () {
var myData = $(this).parent().parent().attr("id");
$.post("/Admin/EditUser", { UserID: myData },
function (data) {
$('#EditUser').html(data);
$('#EditUser').dialog({
modal: true,
width: 400,
resizable: false,
buttons: {
"Save": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
}); //end post
});
部分页面 /Admin/EditUser 如下所示:
@model TourSystem2.Models.UserEditViewModel
<link href="/Content/UserEdit.css" rel="stylesheet" type="text/css" />
@Html.HiddenFor(Model => Model.UserInfo.iUserID)
<table id="useredit">
<tr>
<td>@Html.LabelFor(Model => Model.UserInfo.cLoginName, "Login Name")</td>
<td>@Html.TextBoxFor(Model => Model.UserInfo.cLoginName)</td>
</tr>
//Snip more fields
</table>
我的 EditUser 控制器代码如下所示:
public ActionResult EditUser(int UserID)
{
UserEditViewModel myUser = new UserEditViewModel();
if (UserID == 0)
{
myUser.UserInfo.iUserID = 0;
return PartialView("UserEdit", myUser);
}
else if (myUser.Load(UserID))
{
return PartialView("UserEdit", myUser);
}
else
{
return Json("Broken: " + myUser.Debug);
}
}
我的意图是在点击保存后,我会再做一个 AJAX 帖子以将信息传回服务器。
到目前为止,一切都运行良好,除了文本框的 value 属性没有改变,即使框中的文本发生了变化。如果我单击编辑,数据文件会在 editUser 部分页面上正确输出...但任何更改都不会反映在值中。
使用 firebug,我可以直观地看到屏幕上的任何文本框的值都不会改变。在“保存用户”的帖子中,只返回原始值,不返回修改后的值。
我错过了一些非常基本的东西吗?
*编辑 1*** 我试图在我的 SaveButton 事件中执行以下操作:
"Save": function () {
var myUser =
{
iUserID: ('#UserInfo_iUserID').val,
cLoginName: ('#UserInfo_cLoginName').val,
};
$.ajax({
type: "POST",
url: "/admin/SaveUser",
data: myUser,
success: function (bNum) {
alert("returned" + bNum);
}
});
我得到了 cLoginName 的旧结果:('#UserInfo_cLoginName').val
这发生在第二次 POST 之前。
【问题讨论】:
-
添加编辑1...仍在学习系统。
标签: asp.net-mvc-3 textbox