从CSHTML DATAS传递到自定义编辑不工作 [英] Passing Datas from cshtml to custom edit for not working

查看:141
本文介绍了从CSHTML DATAS传递到自定义编辑不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 .cshtml 我的code。我想CSS的值传递给我的,但自定义编辑无法正常工作。

  @ Html.EditorFor(型号=> model.xxx,新{大小= 20,最大长度= 10,CSS =测试})

我的code在自定义编辑的。

  @model串@ {
    INT大小= 50;
    INT最大长度= 50;
    字符串类型=文本;
    字符串的CSS =;    如果(计算机[大小]!= NULL)
    {
        大小=(INT)计算机[大小];
    }
    如果(计算机[最大长度]!= NULL)
    {
        最大长度=(int)的计算机[最大长度];
    }
    如果(计算机[型]!= NULL)
    {
        类型=(字符串)计算机[型];
    }
    如果(计算机[CSS]!= NULL)
    {
        CSS =(字符串)计算机[CSS];
    }
}
@ Html.TextBox(,模型,新的{大小=大小,最大长度=最大长度,类型=类型,@class = CSS})


解决方案

嗯,我重现MVC 4你的榜样,我想你应该逃避 CSS 属性名 EditorFor 赫普勒因为那时它的作品。在这里,您是:

  @ Html.EditorFor(型号=> model.xxx,新{大小= 20,最大长度= 10,@css =测试})

This is my code in .cshtml. I want to pass value of css to my custom edit for but not working.

 @Html.EditorFor(model => model.xxx, new { size = 20, maxLength = 10 , css = "test"  })

my code in custom edit for.

@model string

@{
    int size = 50;
    int maxLength = 50;
    string type = "text";
    string css = "";

    if (ViewData["size"] != null)
    {
        size = (int)ViewData["size"];
    }
    if (ViewData["maxLength"] != null)
    {
        maxLength = (int)ViewData["maxLength"];
    }
    if (ViewData["type"] != null)
    {
        type = (string)ViewData["type"];
    }
    if (ViewData["css"] != null)
    {
        css = (string)ViewData["css"];
    }
}
@Html.TextBox("", Model, new { Size = size, MaxLength = maxLength, Type = type, @class = css})

解决方案

Well i reproduce your example on MVC 4 and i suppose you should just escape css property name in EditorFor hepler for then it works. Here you are:

@Html.EditorFor(model => model.xxx, new { size = 20, maxLength = 10 , @css = "test"  })

这篇关于从CSHTML DATAS传递到自定义编辑不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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