简体   繁体   中英

Is Model required or Optional in ASP.Net MVC?

I have a requirement to upload a excel file to the server, read contents, perform some validation and return those contents to the browser in raw html format. My question is that what if My Controller can read the contents of the file and build html dynamically and sending the html content back to the client. Here Model is not being used, is it a bad design pattern?

Render your desired Html at Server Side in a single string then put it in a Model with only one string , then send it to View and show it using Html.Raw() as following concept:

Model:

public class RenderedHtmlViewModel
{
      public string RenderedHtml {get;set; }
}

View:

@Html.Raw(Model.RenderedHtml)

You should avoid doing this. You should construct a model based on the Excel file contents, and then you should create a view based on that model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM