设置"id"和“名称" @HtmlEditorFor? [英] set "id" and "name" for @HtmlEditorFor?

查看:172
本文介绍了设置"id"和“名称" @HtmlEditorFor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为@Html.EditorFor设置idname,但这不起作用:

I'm trying to set id and name for @Html.EditorFor, but this isn't working:

@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"})

如何设置idname?

推荐答案

EditorFor不允许添加htmlAttributes.对于特定类型的编辑器,您必须使用TextBoxFor(或使用的任何类型).

EditorFor does not allow for adding htmlAttributes. For the specific types of editors you'll have to use TextBoxFor (or whatever type you're using).

@Html.TextBoxFor(m => m.value, new { id = "testid1", name="Testname1" })

您还可以创建

You can also create a custom editor template for the particular type you're creating an editor for.

这篇关于设置"id"和“名称" @HtmlEditorFor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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