Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc MVC 5.1-使用自定义编辑器模板在EditorFor中添加Html属性_Asp.net Mvc_Razor_Asp.net Mvc 5.1 - Fatal编程技术网

Asp.net mvc MVC 5.1-使用自定义编辑器模板在EditorFor中添加Html属性

Asp.net mvc MVC 5.1-使用自定义编辑器模板在EditorFor中添加Html属性,asp.net-mvc,razor,asp.net-mvc-5.1,Asp.net Mvc,Razor,Asp.net Mvc 5.1,我可以添加htmlAttributes,如以下内容及其在Html中的呈现 @Html.EditorFor(Function(model) model.LastName, New With {Key .htmlAttributes = New With {Key .ng_model = "model.LastName"}}) 但当我在Views\Shared\EditorTemplates\Date.vbhtml中为日期数据类型添加自定义编辑器模板时,如下所示 @Code Dim val

我可以添加htmlAttributes,如以下内容及其在Html中的呈现

@Html.EditorFor(Function(model) model.LastName, New With {Key .htmlAttributes = New With {Key .ng_model = "model.LastName"}})
但当我在
Views\Shared\EditorTemplates\Date.vbhtml
中为日期数据类型添加自定义编辑器模板时,如下所示

@Code
    Dim value = ""
    If Not Model Is Nothing Then
        value = String.Format("{0:d}", Model.Value.ToString("dd/MM/yyyy"))
    End If
    @Html.TextBox("", value, New With {Key .class = "datefield", Key .type = "text"})
End Code

我将EditorFor与htmlAttributes一起使用,然后htmlAttributes不呈现?

这是我用于自定义DateTime编辑器模板的代码示例。我能够访问传递到editorfor的htmlattributes。希望这有帮助

@model DateTime

@{
    object htmlAttributes = null;
    if (ViewContext.ViewData.Keys.Contains("htmlAttributes"))
    {
        htmlAttributes = ViewContext.ViewData["htmlAttributes"];
    }
}

@Html.TextBoxFor(model => model, htmlAttributes)

也许一个好主意是发布渲染的内容,而不是说它不是渲染。