HTML.Editor添加类不工作 [英] HTML.EditorFor adding class not working

查看:122
本文介绍了HTML.Editor添加类不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题添加css类到HTML.EditorFor()。我在网上搜索,如果有人有同样的问题,但我找不到任何东西。

I have problem with adding css class to HTML.EditorFor(). I was searching on the net if someone had the same problem but I couldn't find anything.

你能帮我吗?所以,它的css没有类的问题没有定义,它是,但简单地说,它没有添加到输入字段。
这是视图中的代码:

Can you please help me? So, its not problem about css that class is not defined, it is, but simply, its not added to input field. This is the code in view:

@model eVinogradarstvo.Models.DetaljiViewModel

@{
    ViewBag.Title = "Edit";
}

@using (Html.BeginForm("PromijeniPodatke", "KorisnikDetalji", FormMethod.Post, new { enctype = "multipart/form-data",@class="form-horizontal" }))
{
@Html.AntiForgeryToken()

<div class="col-sm-12">
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.kd.id)
    @Html.HiddenFor(model => model.kd.korisnik_id)
    @Html.HiddenFor(model => model.kd.slika)
    @Html.HiddenFor(model => model.kd.dokument_id)
    <table class="table table-responsive">
        <tr>
            <td>Slika profila</td>
            <td><input type="file" name="uploadImages" class="input-files" /></td>
        </tr>
        <tr>
            <td>@Html.DisplayNameFor(model => model.kd.ime)</td>
            <td>
                @Html.EditorFor(model => model.kd.ime, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.kd.ime)
            </td>
        </tr>
        <tr>
            <td>@Html.DisplayNameFor(model => model.kd.prezime)</td>
            <td>
                @Html.EditorFor(model => model.kd.prezime, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.kd.prezime)
            </td>
        </tr>
        <tr>
            <td>@Html.DisplayNameFor(model => model.kd.adresa)</td>
            <td>
                @Html.EditorFor(model => model.kd.adresa, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.kd.adresa)
            </td>
        </tr>
        <tr>
            <td>@Html.DisplayNameFor(model => model.kd.grad)</td>
            <td>
                @Html.EditorFor(model => model.kd.grad)
                @Html.ValidationMessageFor(model => model.kd.grad)
            </td>
        </tr>
        <tr>
            <td>@Html.DisplayNameFor(model => model.kd.drzava)</td>
            <td>
                @Html.EditorFor(model => model.kd.drzava)
                @Html.ValidationMessageFor(model => model.kd.drzava)
            </td>
        </tr>
        <tr>
            <td>@Html.DisplayNameFor(model => model.kd.datum_rodenja)</td>
            <td>
                @Html.EditorFor(model => model.kd.datum_rodenja)
                @Html.ValidationMessageFor(model => model.kd.datum_rodenja)
            </td>
        </tr>
        <tr>
            <td>Mjerna jedinica težine</td>
            <td>
                @Html.DropDownListFor(model => model.kd.mj_tezine, new SelectList(Model.DDLtezina, "vrijednost", "opis"))
                @Html.ValidationMessageFor(model => model.kd.mj_tezine)
            </td>
        </tr>
        <tr>
            <td>Mjerna jedinica tekućine</td>
            <td>
                @Html.DropDownListFor(model => model.kd.mj_tekucine, new SelectList(Model.DDLtekucina, "vrijednost", "opis"))
                @Html.ValidationMessageFor(model => model.kd.mj_tekucine)
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="Spremi" class="btn btn-default" /></td>
        </tr>
    </table>
</div>

}

p>

推荐答案

EditorFor在ASP.NET MVC 3不支持以这种方式传递CSS到生成的HTML。您必须创建自定义编辑器模板并传递自定义ViewData条目,并手动执行(如上面显示的链接答案)。

EditorFor in ASP.NET MVC 3 does not support passing CSS to the generated HTML in this manner. You have to create a custom editor template and pass custom ViewData entries and do it manually (as the linked answers above show).

这在MVC 5.1中已更正,如果你不愿意创建自己的模板,那么就无法在MVC 3中使用EditorFor。

This was corrected in MVC 5.1, but there is no way to make this work in MVC 3 with EditorFor if you aren't willing to create your own templates.

这篇关于HTML.Editor添加类不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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