开发者

Using EditorFor in ASP.NET MVC 2.0 to render a span

I have a complex object that if I render in this way:

<%=Html.EditorFor(x => x.ContactRoleDto.Competencies[0].Name) %>

The above generates the following element which has the name and id tags that I want:

<input Size="40" id="ContactRoleDto_Name" maxlength="100" name="ContactRoleDto.Name" type="开发者_JS百科text" value="" />

I would like to render a tag with the correct id and name attributes that are in the same form as above, i.e. ContactRoleDto.Competencies[0].Name".

How is the best way to achieve this?

All I really want is the ability to pull out the correct id and name fields that will help me model bind a table that is dynamically generated or rendered.

Is ModelMetaData the best way to go, I do not want to go the UIHint route.


You could use the ExpressionHelper.GetExpressionText method. For example:

Expression<Func<string, YourModel>> expression = x => x.ContactRoleDto.Competencies[0].Name;
string id = ExpressionHelper.GetExpressionText(expression);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜