mvc 4中的服务器端验证不显示错误

时间:2013-01-11 12:03:59

标签: c# asp.net-mvc razor asp.net-mvc-4 server-side-validation

任何人都可以告诉我为什么当我关闭javascript时,下面的代码没有返回错误消息,我正在检查以确保服务器端验证有效。

我可以在Modelstate.isvalid上设置断点并查看错误消息。

@model Web.Domain.WeightsAndMeasures.DisplayWeightsAndMeasures

<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

@using (Html.BeginForm("CalculateWeightOrMeasure", "WeightsMeasures", FormMethod.Post, new { @id = "frmWeightsMeasures" }))
{
@Html.ValidationSummary(true)

<fieldset>
    <legend>DisplayWeightsAndMeasures</legend>

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

    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>
}

[HttpPost]
    public ActionResult CalculateWeightOrMeasure(FormCollection fc, DisplayWeightsAndMeasures model)
        {
         if (ModelState.IsValid)
            {
            var data = _IGWAM.GetWeightsMeasures();
            string ConvertFrom = fc["dblValueToConvert"];
            return PartialView("WeightOrMeasureForm", model);
                 }
         return View("~/Views/Home/Index.cshtml", model); <--This does not work
         //return PartialView("WeightOrMeasureForm", model); <--This does work, 
        }

我正在使用MVC4

由于

乔治


    <div id="dvOuterCase">
<div id="dvPageVideo">
    <div id="myElement">Loading the player...</div>
    @{Html.RenderPartial("~/Views/Video/_pvVideoAdvert.cshtml");}
</div>
<div id="dvHomeAdverts">
    @{Html.RenderAction("TopAdvert", "Advertise");}
</div>
</div>
<div id="dvGlobalBody">
<div id="dvHomeCatergories">
    <div class="clHomeLeft">
        <div class="clHomeLeftInner">
            @{Html.RenderAction("HomeWeather", "Weather");}
        </div>
        <div class="plil">
            <h1>Convertor</h1>
            @{Html.RenderAction("WeightOrMeasureForm", "WeightsMeasures");}
        </div>
    </div>
    <div class="clHomePageCentre">
        <div class="clHomeInnerTop">
            <h1>Directory</h1>
            <ul>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="pli">
            <h1>Your Reviews</h1>
        </div>
    </div>
    <div class="clHomePageRight">
        <div class="clHomePageRightTop">
            @{Html.RenderAction("Currency", "Currency");}
            <div id="dvCurrencyResults">
                <p id="DisplayCurrency">@ViewBag.DisplayExchange</p>
                <p id="DisplayCurrencyReverse">@ViewBag.DisplayExchangeReverse</p>
            </div>
        </div>
        <div class="plir">
            <h1>Travel News</h1>
            <p>1</p>
            <p>2</p>
        </div>
    </div>
</div>

0 个答案:

没有答案