これはViewViewPage.cshtmlです
@using (Html.BeginForm("Display", "Home", FormMethod.Post))
{
<div>Name:<a>@ViewBag.st</a><br /></div>
<input type="submit" value="Submit" />
<br />
}
@ViewBag.st を編集するための私の jquery
<script type="text/javascript">
$(document).ready(function () {
$('a').click(function () {
var textbox = $('<input id="Text1" type="text" size="100" />')
var oldText = $(this).text();
$(this).replaceWith(textbox);
textbox.blur(function () {
var newValue = $(this).val();
$(this).replaceWith($('<a>' + newValue + '</a>'));
});
textbox.val(oldText);
});
});
</script>
私のコントローラーメソッドは
public ActionResult Viewdetails()
{
User ur = new User();
ur.Name = "Danny";
ViewBag.st = ur.Name;
return View();
}
そして、私のモデル クラスは User.cs です
public class User
{
//public string name { get; set; }
private string m_name = string.Empty;
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
}
}
}
@ViewBag.title を編集した後、その値を保存して次のビューに渡したい