如何设置ID使用Html.EditorFor与MVC3 [英] How can I set id using Html.EditorFor with MVC3

查看:371
本文介绍了如何设置ID使用Html.EditorFor与MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个id字段如下:

I am trying to set a field id as follows:

@Html.EditorFor(x => x.Order, new { id = string.Format("Order_{0}", Model.Row) })

但这会导致以下,似乎我的ID没有被设置:

but this results in the following and it seems my id is not being set:

<input type="text" value="334" name="item.Order" id="item_Order" class="text-box single-line">

没有任何人有一个想法是什么,我做错了。我检查了允许的格式EditorFor,并期待在谷歌的例子,但我不能看到任何匹配我需要什么。

Does anyone have an idea what I am doing wrong. I checked the allowable formats for EditorFor and looked on google for examples but I could not see anything that matched what I need.

推荐答案

您应该改为

@Html.TextBoxFor(x => x.Order, new { id = string.Format("Order_{0}", Model.Row) })

@ Html.EditorFor 的第二个参数是视图数据,而不是HTML属性

The second parameter of @Html.EditorFor is for view data, not for html attributes

这篇关于如何设置ID使用Html.EditorFor与MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆