0

我对正在发生的事情感到非常困惑。所以 Go 是一个布尔变量,在我的模型中 Go 当前结果为真。为什么这两个会导致不同的值?

@Html.TextBoxFor(m => m.Go); 
@Model.Go;
@Html.CheckBoxFor(m => m.Go);

@Html.TextBoxFor(m => m.Go) 结果为 FALSE
@Html.CheckBoxFor(m => m.Go) 结果为 UNCHECKED 框(当我预期为选中框时)
@Model.Go 结果为 TRUE(我期望发生的事情)

@Html.TextBoxFor(m => m.Go) 怎么会是假的?
以及
为什么 @Html.CheckBoxFor(m => m.Go) 会导致一个 UNCHECKED 框。非常感谢!

我的控制器

    [HttpPost]
    public ActionResult IXT_FS_LeakCheckAnode(IXT_FS_LeakCheckAnodeModel model, string buttontype)
    {
        model.FormObject = new FormSubmitObject();
        // If the Go has been hit, set the FormObject go be true also.
        if (model.Go) { model.FormObject.go = true; }
        // Add values if necessary, If its not on a submit it will be okay, because it     will not submit in the model.
        List<string> list = new List<string>();
        list.Add("SNT" + model.MainSerial);
        list.Add("USR" + model.BadgeID);
        list.Add("TMS" + 0);

        model.FormObject.MainSerial = model.MainSerial; // Sets the main serial

        model.FormObject = mm.submitGetFormHelper(model.FormObject, "XFA", list, ModelState.IsValid, buttontype);
        if (model.FormObject.checkmsg == "go_pass")       // Update header info.
        {
            model.TubeType = model.FormObject.form_values_dict["TUT"];
            model.FormObject.go = true;
            model.Go = true;
        }
        else if (model.FormObject.checkmsg == "get_pass")  // Update the empty filled.
        {
            model.BadgeID = model.FormObject.form_values_dict["USR"];
            model.MainSerial = model.FormObject.form_values_dict["SNT"];

            // Grabs the TMS double value and converts it into a Time Stamp.
            double latestDate_dbl = Convert.ToDouble(model.FormObject.form_values_dict["TMS"]);
            DateTime latestDate = mm.parseTimeStamp(latestDate_dbl);
            model.LatestDate = "Completed on: " + latestDate.ToString();
            ViewData["Error"] = model.FormObject.errormsg;
        }
        else if (model.FormObject.checkmsg == "submit_pass" || model.FormObject.checkmsg == "clear_pass")// Clear form and let operator submission passed. or clear button
        {
            ModelState.Clear();
            IXT_FS_LeakCheckAnodeModel clear_model = new IXT_FS_LeakCheckAnodeModel();
            return View(clear_model);
        }


        ViewData["Error"] = model.FormObject.errormsg;

        return View(model);
    }
4

2 回答 2

1

更有可能的是,您在 ViewBag 或 ViewData 中有一个名为 Go 的东西,它正在干扰事物。在渲染时,MVC 更喜欢模型状态而不是模型值。

于 2012-08-16T18:41:11.927 回答
0

我相信对于布尔值,您可能应该考虑使用复选框而不是文本框。如果您尝试:

@Html.EditorFor(m=>m.Go)
于 2012-08-16T18:45:51.433 回答