asp.net mvc Html.Textbox, unable to set value?
in my route table I have this entry
routes.MapRoute(
"myRoute",
"route/{controller}/{action}/{id}/{start}/{end}",
new { controller = "Home", action = "Index", id = "", start="", end="" }
);
in my master page I have a line of code like so:
<%= Html.TextBox("foo", "bar") %>
If I access the page in the form of http://mysite.com/route/Home/Index/id/start/end the textbox renders OK with a value of "bar" However if I access the page using the default parameters http://mysite.com/route/ the textbox does not have a value! In the emitted HTML it shows up like so:
<input id="foo" type="text" va开发者_高级运维lue="" name="foo"/>
it didn't set the value to "bar"...is this a bug? or is this not allowed in mvc master pages?
it should work fine
" <%= Html.TextBox("name", "Please enter your name...")%>
Output : < input id="name" name="name" type="text" value="Please enter your name..." />
<%: Html.TextBox("foo", "bar") %>
sometimes you need to force it to be a simple html attribute as follows
<%: Html.TextBox("foo", null,new{value="bar"}) %>
精彩评论