I am trying to return the parent View when I call an ActionResult from within a Partial View. If I know the parent view I can just type in return View("Index");, but I can't because their could be multiple parent views as this partial view is shared... So how 开发者_开发问答do I return the correct parent View in the ActionResult?
This seems so simple, but it has me stumped...
Update. Here is the Partial View:
@model Website.Models.PostModel
@using (Html.BeginForm("SubmitPost", "Home", FormMethod.Post))
{
@Html.TextAreaFor(m => m.Message, 2, 50, null)
<br /><br />
<div class="ui-widget">
Notes: @Html.TextBox("Notes", "", new { @class = "ui-autocomplete-input" })
</div>
<br />
<p>
<input type="submit" value="Post" />
</p>
}
I assume you're using @{Html.RenderAction("Action");}
in your view to call
[ChildActionOnly]
public ActionResult Action()
{
var model = context.Data.Where(x => x);
return PartialView("PartialView", model);
}
if so, then you could specify your routeValues as well. In your view you would call
@{Html.RenderAction("Action", new {viewName = "parentView"});}
and in you controller:
[ChildActionOnly]
public ActionResult Action(string viewName)
{
var model = context.Data.Where(x => x);
if (model == null) return View(viewName);
return PartialView("PartialView", model);
}
精彩评论