我的jQuery是
<script type="text/javascript">
$(document).ready(function () {
$('p').click(function () {
var textbox = $('<input id="Text1" type="text" name="Name" />')
var oldText = $(this).text();
$(this).replaceWith(textbox);
textbox.blur(function () {
var newValue = $(this).val();
$(this).replaceWith($('<p>' + newValue + '</p>').after($('<input id="Text1" type="text" name="Name" />',{ type: 'hidden', name: 'Name', value: newValue })));
});
textbox.val(oldText);
});
});
</script>
然后进行 2 个控制器操作(GET 和 POST):
public ActionResult Viewdetails()
{
User ur = new User();
ur.Name = "Danny";
return View(ur);
}
[HttpPost]
public ActionResult Display(User model)
{
return View(model);
}
在里面Viewdetails.cshtml
:
@model User
@using (Html.BeginForm("Display", "Home", FormMethod.Post))
{
<div>Name: <a>@Model.Name</a><br /></div>
<input type="submit" value="Submit" />
<br />
}
在里面Display.cshtml
:
@model User
<div>You have selected: @Model.Name</div>
我无法在运行时编辑名称,这在 mvc3 中运行良好