gpt4 book ai didi

HTML.EditorFor 添加类不起作用

转载 作者:太空狗 更新时间:2023-10-29 15:49:42 25 4
gpt4 key购买 nike

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

你能帮帮我吗?因此,未定义类不是 css 的问题,而是简单地说,它没有添加到输入字段中。这是 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>

有什么建议吗?

最佳答案

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

这在 MVC 5.1 中已得到纠正,但如果您不愿意创建自己的模板,则无法在 MVC 3 中使用 EditorFor 进行此操作。

关于HTML.EditorFor 添加类不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27926236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com