如果要刷新页面:
控制器:
public ActionResult Index(){ return View();}public ViewResult Test(){ ViewBag.Name = Request["txtName"]; return View();}Index.cshtml:
@using (Html.BeginForm("Test", "Home", FormMethod.Post )){ <input type="submit" id="btnSearch" value="Search"/> <label>Name:</label><input type="text" id="txtName" name="txtName" />}Test.cshtml:
@ViewBag.Name
============================================
如果您不想刷新页面:
控制器:
public ActionResult Index(){ return View();}[HttpPost]public PartialViewResult TestAjax(string Name){ ViewBag.Name = Name; return PartialView();}Index.cshtml:
<input type="button" id="btnSearch" value="Search"/> <label>Name:</label><input type="text" id="txtName" name="txtName" /><script>$('#btnSearch').click(function () { $.ajax({ url: '@Url.Action("TestAjax", "Home")', data: { Name: $("#txtName").val() }, type: 'POST', success: function (data) { $("#divContent").html(data); } });});</script>TestAjax.cshtml:
@ViewBag.Name



