Reputation: 2985
Is it a common practice, that models in asp.net mvc x could create/produce/return html markup?
Model-class:
public interface IMyModel {
MvcHtmlString GetGrid(string gridId, HtmlHelper htmlHelper);
}
public class MyModel<TRowModel> : IMyModel {
IList<TModel> GridItems{get;set;}
public MvcHtmlString GetGrid(string gridId, HtmlHelper helper){
WebGrid<TRowModel> webGrid = new WebGrid<TRowModel>(gridId, GridItems)
return webGrid.GetHtml(helper);
}
}
View:
@model IMyModel
@Model.GetGrid("grid", Html)
Upvotes: 1
Views: 488
Reputation: 776
As per MVC pattern, Model should be dumb and should be acting more as containing business domain object. Technically it is possible to send data as HTML in Model but ideally it should be the duty of View to send HTML markup... Model will be inserting data into that HTML markup.
Upvotes: 2