volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Override view with different model


Model PageType:SamplePage.cs
public virtual XhtmlString MainBody { get; set; }

Controller: SamplePageController.cs
public ActionResult Index(SamplePage currentPage)
{
PageViewModel model = new PageViewModel(currentPage);
return View(model);
}

SamplePage/Index.cshtml
@model EPiServerSite1.Models.ViewModels.PageViewModel

The above works fine. 


But I am trying to send a different view in the controller like below:

public ActionResult Index(SamplePage currentPage)
{
List data = new List(Getvalues());
return View(model);
}

where

public class ABCBlockModel
{
public string Name { get; set; }
public double Score { get; set; }
public string Sector { get; set; }
}


so the Index can have
@model IEnumerable

But the view the tightly bound with SamplePage it seems. Can the view have 'ABCBlockModel'

#113444
Nov 20, 2014 14:41

Hi,

I think what you're looking for is something called a "viewmodel". A viewmodel is a model that you instantiate and populate based on your model and/or any other data you need the view to know about. Please read more about here -> http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc

#113452
Nov 20, 2014 19:19
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.