stacker
stacker

Reputation: 14931

HtmlHelper NameFor method

Is there an Html.NameFor feature, that gets the name html attribute for a model item?

I'd like to use the following code in my Razor view:

<input type="text" value="@Model.User.Email" name="@Html.NameFor(x => x.User.Email)">

Upvotes: 11

Views: 7364

Answers (3)

stacker
stacker

Reputation: 14931

Yes, there is Html.NameFor method in the ASP.NET MVC Futures assembly.

Upvotes: 6

Mike
Mike

Reputation: 7701

Html.NameFor is now included in MVC 4.

Upvotes: 12

marcind
marcind

Reputation: 53183

If you just want to get the value for a name attribute that will work when binding the input back to your model you could use the ExpressionHelper.GetExpressionText method. However invoking it would involve some code gymnastics.

How about just using the TextBoxFor helper?

@Html.TextBoxFor(Model => Model.User.Email)

Upvotes: 3

Related Questions