We're trying to be type-safe in our views and use the new ExpressionInputExtenssion HtmlHelpers, but we are seeing some inconsistent results. We have a view that looks like this:
ViewData.Model.FooID = <%= ViewData.Model.FooID %><
Model.FooID = <%= Model.FooID %>
<%= Html.HiddenFor(x=>x.FooID) %>
But what we see in the rendered view is this:
ViewData.Model.FooID = 515b0403-e75b-4bd7-9b60-ef432f39d338
Model.FooID = 515b0403-e75b-4bd7-9b60-ef432f39d338
<input id="FooID" name="FooID" type="hidden" value="" />
I can manually add this:
<input id="FooID" name="FooID" type="hidden" value="<%= Model.FooID %>" />
But now we are no longer, but surprisingly when I do, The Html.HiddenFor always has the correct value.
HiddenFor() The Html. HiddenFor<TModel, TProperty> extension method is a strongly typed extension method generates a hidden input element for the model property specified using a lambda expression. Visit docs.microsoft.com to know all the overloads of HiddenFor() method.
It creates a hidden input on the form for the field (from your model) that you pass it. It is useful for fields in your Model/ViewModel that you need to persist on the page and have passed back when another call is made but shouldn't be seen by the user.
An HTML Helper is just a method that returns a HTML string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML <input>, <button> and <img> tags etc.
Take a look at this: http://blogs.msdn.com/b/simonince/archive/2010/05/05/asp-net-mvc-s-html-helpers-render-the-wrong-value.aspx
It looks like the model binder that is behind the extension method cannot convert you FoodID datatype to a string. Is your data type a regular GUID?
I known there are overloads for this extension method for working with binary but I'm not sure about GUIDs ....
Have u tried debbuging it?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With