我已经阅读了关于如何更新局部视图的一些教程,但他们都假设用户交互作为起点(如下拉更改将导致部分视图中的某些数据更新) 。我的情况有所不同:我试图从控制器开始更新局部视图,而无需用户在UI上进行交互。如果我使用这样的代码:从控制器更新部分视图
[HttpPost]
public ActionResult PerformAction(MyModel mymodel)
{
//....do things
return PartialView("Notification", mymodel);
}
浏览器将只显示局部视图。建议?由于
以下是主要观点:
@using System.Web.UI.WebControls
@model MyApplication.Models.Mymodel
@{
ViewBag.Title = "Home Page";
}
<form class="float_left" method="post" action="@Url.Action("Start", "Home")">
<fieldset>
@Html.TextBoxFor(m => m.Username, new { Value = Model.Message })
<input type="submit" value="Subscribe"/>
<div id="notificationMessage">
@{ Html.RenderPartial("~/Views/Home/PartialView.cshtml", new PartialViewModel()); }
</div>
</fieldset>
</form>
,这里的部分:
@using System.Web.UI.WebControls
@model HostedExchangeListener.Models.PartialViewModel
@Html.TextBoxFor(m => m.Message, new { Value = Model.Message })
因为您的东西的声音好像你要使用AJAX呈现局部视图返回'PartialView'?所以它不会重新加载页面 –
在教程中,我看到使用了Ajax,但它假定页面上有一些用户交互。 – user1472131
那么有几种方法,您可以在DOM加载时在部分视图中加载时使用ajax,或者您可以将模型传递给部分视图。你可以发布你的视图,你想渲染的部分,也是你的部分。 –