开发者

Generating html tags programmatically

I'm not sure if this is the best solution design.开发者_Python百科 But i would like to know how to add code in view to generate tags like div,p,span etc and also define there attributes programmatically.

For example i have a list of objects that i pass it as Model and then calculate width of div to be generated dynamically from number of objects and then generated div for each object. Div ids would also need to be controlled like div_1,div_2 and also if i could set other attributes like class from the helper directly.

So far i've seen example of Html helper for controls only like textbox and listbox. I am not being able to intuitively think about autogenerated div, span etc.

I'm still a beginner in mvc and it seems like i'm asking something different from similar titled questions. Pardon me if i'm wrong.

Thank you.


I think you need to take a look at how to create your own html helper.

they work in much the same way as Html.Textbox etc except they are your own that will create your specific control needs.

http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs

and this one from ScottGu

http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx

Also, when defining widths post render you may want to create a jQuery plugin that can set attributes etc.

And seeing as you are a beginner take a look at this site. I think it's where we all start.

http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx


U Can Assign These Tags to variables and Then use them Programatically.. In fact it is always better way to write those tags manually coz there is always a need to use a closing tag at the end and u need to store that in another variable.. and variables will take some memory and will become a adhac for you... And Adventage for using direct tags is that your IDE also supports them and make it easy for u programme tags rather than using variables for these tags... I hope is The Answer of Your Question

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜