What is the best way to get HTML programmatically in the view from the controller.
I sometimes use string builder for that to render some html and send it the view from the controller.is it efficient?
What do you people suggests?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
HtmlHelpers are meant for that. A better option is to create an HtmlHelper that will generate the tag you you need and all you do is pass an object to it (from the Model or ViewData in the view) and it outputs the proper tag for you. There is a
TagBuilderobject that will streamline everything you need.Then in your view:
This is just a quick example, you can extrapolate it to your liking.
Search
asp.net mvc html helpersto understand how this works and how extension methods work.