kalki
kalki

Reputation: 13

MVC & SelectList

Is there a way to output select list to a string in the View ?

//Javascript
var comboHtml = <%= Html.Encode(Model.MySelectList.ToHtml()) %> 

or would i have to enumerate the list my self to create the html,

need this for a dynamic form field.

Upvotes: 1

Views: 419

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

var comboHtml = '<%= Html.DropDownList("name", Model.MySelectList) %>';

Upvotes: 2

Jimmeh
Jimmeh

Reputation: 2862

You could use ajax and Html.RenderPartial.

(assuming mvc.net btw)

Also, the issue with doing it in Javascript is that the <%= stuff here %> would render the string at the page load.

Upvotes: 0

Related Questions