开发者

ASP.NET MVC strongly typed helpers generate wrong input nam when are used inside foreach

开发者 https://www.devze.com 2023-01-10 02:56 出处:网络
I\'ve got a problem with ASP.NET mvc stongly typed helpers. Here is example of wrong behavior: <% foreach (var item in Model) { %>

I've got a problem with ASP.NET mvc stongly typed helpers.

Here is example of wrong behavior:

<% foreach (var item in Model) { %>
   <开发者_C百科;%: Html.TextboxFor(m => item.Name) %>
<% } %>

will generate following inputs: <input name="item.Name".....

As you see generated name is wrong, because of wrong algorithm of extracting property name from lambda.

The only way to avoid this bug is to create PartialView and pass item as its context.

May be somebody knows other solutions?

Regards, Alexey Zakharov.


Why just not <%= Html.TextboxFor(item.Name) %> ?

0

精彩评论

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