在绑定MVC 4上更改了双值

时间:2014-06-14 14:02:33

标签: c# .net asp.net-mvc asp.net-mvc-4 data-binding

我的问题是我有3个双字段,当我尝试绑定这些值时,它会更改文本框中键入的值。

这样的事情:

Typed Value 5.4

Binded Value 54.0

这是我的代码:

查看

<div class="row jumbotron">
<div class="col-md-5">
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <h2>@ViewBag.Title</h2>

        <div class="row">
            <div class="col-md-12">

                @Html.Hidden("customerId", new { customerId = ViewBag.customerId })
                @Html.Hidden("jobOffertId", new { jobOffertId = ViewBag.jobOffertId })

                <label>Descrição: </label>
                @Html.TextBoxFor(model => model.Description, new { @class = "form-control" })

                <label>Confiança: </label>
                @Html.TextBoxFor(model => model.TrustPoints, new { @class = "form-control review" })

                <label>Qualidade do serviço: </label>
                @Html.TextBoxFor(model => model.QualityPoints, new { @class = "form-control review" })

                <label>Pontualidade: </label>
                @Html.TextBoxFor(model => model.PunctualityPoints, new { @class = "form-control review" })

            </div>
        </div>
        <br/>
        <div class="row">
            <div class="col-md-4">
                <input class="btn btn-default" type="submit" value="Criar avaliação" />
            </div>
        </div>
    }
</div>

POST方法

    [HttpPost]
    public ActionResult CreateJobReview(JobReviewModel jobReviewModel, FormCollection data)
    {
        initBusinessObjects();

        Util.Common.ChangeContextInstance(null,null,null,jobOffertBusiness,jobReviewBusiness);

        var customerId = int.Parse(data["customerId"]);
        var jobOffertId = int.Parse(data["jobOffertId"]);

        var jobOffert = jobOffertBusiness.GetById(jobOffertId);

        jobReviewModel.JobOffert = jobOffert;

        jobReviewBusiness.Insert(jobReviewModel);

        return RedirectToAction("ViewAllJobOfferts", new { customerId = customerId });
    }

修改

我几乎忘了,如果我只输入:5它正确绑定(5.0)

0 个答案:

没有答案