I am trying to render a 'strongly-typed' grid in my mvc application but I am having trouble using GetGridHtml() when using @model in my view. Below is my work around for now but I'd like to keep everything in partial view if I can.
ViewModel
public class NewsDetailViewModel
{
public int NewsID { get; set; }
public string Title { get; set; }
public DateTime PublishedDate { get; set; }
public NewsDetailViewModel(int newsId, string title, DateTime publishedDate)
{
NewsID = newsId;
Title = title;
PublishedDate = publishedDate;
}
}
Surface Controller
public ActionResult RenderNewsDetail()
{
var model = GetNewsDetailViewModel();
return PartialView($"{PARTIAL_VIEW_FOLDER}_NewsDetail.cshtml", model);
}
private NewsDetailViewModel GetNewsDetailViewModel()
{
IPublishedContent newsDetail = CurrentPage.AncestorOrSelf("newsDetail");
int newsID = newsDetail.Id;
string title = newsDetail.Value<string>("title");
var date = newsDetail.Value<DateTime>("publishedDate");
NewsDetailViewModel model = new NewsDetailViewModel(newsID, title, date);
return model;
}
How do I render a strongly typed grid using mvc?
I am trying to render a 'strongly-typed' grid in my mvc application but I am having trouble using GetGridHtml() when using @model in my view. Below is my work around for now but I'd like to keep everything in partial view if I can.
ViewModel
Surface Controller
Template
Partial
is working on a reply...