を持っています_Layout.cshtml
。内容は次のとおりです。
...
@RenderSection("MyTitle", required: false)
<div class="innerLR">
<div id="appContent">
@RenderBody()
</div>
</div>
...
アプリケーションを起動すると、このアクションHome/Index
、ビューに移動します
public ActionResult Index()
{
return View(new BaseModel { Title = "Testing"});
}
ビュー Index.cshtml :
@section MyTitle{ @Model.Title }
bla bla bla
現時点では問題ありません。次のように表示されます: Testing + bla bla bla。
リンクをクリックすると Ajax 経由で呼び出しHome/SecondAction
、コントローラーは PartialView を返し、コンテンツをappContent
div に表示します。私はこのように呼び出します:
$.ajax({
url: 'Home/SecondAction',
type: 'POST',
data: {},
success: function (result) {
$(#appContent).html(result);
}
});
アクションは次のとおりです。
public ActionResult SecondAction()
{
return PartialView(new BaseModel { Title = "Other Title" });
}
SecondAction.cshtml は次のとおりです。
@section MyTitle{ @Model.Title }
bla bla again
ここではうまくいきません。エラーが発生しますが、最初のアクションからのテキストはできますが、できません:
その他のタイトル bla bla again
PartialView
再開するには、レンダリングからセクションを返すときに希望します_Layout.cshtml
ありがとう、