小编use*_*756的帖子

@ Html.ValidationMessageFor不工作

嗨,大家好,我看过谷歌,雅虎,无法找到答案,为什么它是我的'@Html.ValidationMessageFor不起作用.当我运行应用程序时没有任何反应它允许输入所有内容.当我尝试编辑下面编辑视图中的项目时,它也会崩溃.我有以下内容:

<div class="editor-label">
       @* @Html.LabelFor(model => model.Posted)*@
    </div>
    <div class="editor-field">
        @Html.HiddenFor(model => model.Posted, Model.Posted = DateTime.Now)
        @Html.ValidationMessageFor(model => model.sendinghome)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Cartypes)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Cartypes)
        @Html.ValidationMessageFor(model => model.Cartypes)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.RegNum)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.RegNum)
        @Html.ValidationMessageFor(model => model.RegNum)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Regprice)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Image)
        @Html.ValidationMessageFor(model => model.Regprice)
    </div>
Run Code Online (Sandbox Code Playgroud)

c# asp.net razor asp.net-mvc-3

4
推荐指数
1
解决办法
3万
查看次数

验证无法使用@ Html.HiddenFor

我有以下代码:

@Html.HiddenFor(model => model.Posted, Model.Posted = DateTime.Now)
Run Code Online (Sandbox Code Playgroud)

但验证不起作用当我运行我的应用程序并尝试编辑或创建项目时崩溃.

public ActionResult Create()
{
    return View(new NewsItem());
}
Run Code Online (Sandbox Code Playgroud)

我在我的控制器和应用程序中也有以下代码,它完全符合我的要求,例如它输入当前日期并保存它但如果我将一个编辑框留空或所有编辑框的空白应用程序崩溃并给出以下错误:

你调用的对象是空的.

我不知道这是什么意思?我认为MVC3 C#提供的默认验证应该有效吗?那有什么不对?有人可以帮忙吗?

/* This line of code is what is provided for validation it is pretty much 
   similar on all the edit, delete and create views. */
@Html.ValidationMessageFor(model => model.Posted)   
Run Code Online (Sandbox Code Playgroud)

c# asp.net razor asp.net-mvc-3

0
推荐指数
1
解决办法
2426
查看次数

标签 统计

asp.net ×2

asp.net-mvc-3 ×2

c# ×2

razor ×2