複数のタイプのページを編集できるセクションの編集画面で、cms を構築しています。URL は次のように自然なままにする必要があります。
foob
ar.com/edit/section/my-content-page-name foobar.com/edit/section/my-gallery-page-name
foobar.com/edit/section/my-blog-page-name
このシナリオでは、Get と Post の両方に Index アクションが使用されます。
現時点では、すべてのページ タイプで必要なすべてのデータを含む 1 つの大規模な ViewModel があります。
これはかなり間違っていると感じており、投稿のページ更新の種類を決定するための醜い解決策になります。
アクションを同じに保ちながら、異なる厳密な型の ViewModel で使用するにはどうすればよいですか?
これは可能ですか?
public ActionResult Index(string page)
{
var model = _pageManager.GetSection(page, SelectedSite);
return View(model.PageType, model);
// renders appropriate View based on page type.
}
[Transaction]
[HttpPost]
[ValidateInput(false)]
public ActionResult Index(SectionIndexViewModel model)
{
// all page types post back to same action to update content etc.
// at this point SectionIndexViewModel is getting bloated with properties because it must cater for ALL page types data.
var action = Request["action"] ?? "";
// currently use this to determine what event has been triggered
switch (action.ToLower())
{
// then goes to update the appropriate page, blog or gallery
// etc.