I have _Layout.cshtml
, the content is :
...
@RenderSection("MyTitle", required: false)
<div class="innerLR">
<div id="appContent">
@RenderBody()
</div>
</div>
...
When I start the application, I go to this action Home/Index
, the view
public ActionResult Index()
{
return View(new BaseModel { Title = "Testing"});
}
The View Index.cshtml :
@section MyTitle{ @Model.Title }
bla bla bla
At this time it's ok, I see the : Testing + bla bla bla.
Now I call Home/SecondAction
via Ajax when I click on a link, the controller return a PartialView and diplay the content in appContent
div.
I call like this:
$.ajax({
url: 'Home/SecondAction',
type: 'POST',
data: {},
success: function (result) {
$(#appContent).html(result);
}
});
The action is :
public ActionResult SecondAction()
{
return PartialView(new BaseModel { Title = "Other Title" });
}
The SecondAction.cshtml is :
@section MyTitle{ @Model.Title }
bla bla again
Here that's not work, I'd have any error but I can the text from the first action and not :
Other Titla bla bla again
To resume I'd like when I return a PartialView
render a section from the _Layout.cshtml
Thanks,