简体   繁体   English

如何在MVC局部视图中显式设置模型的值

[英]How to explicitly set value for a model in MVC partial view

I have a model in a Partial view(Ajax.BeginForm) that has few properties. 我在部分视图(Ajax.BeginForm)中具有很少属性的模型。 Some of them get set by the user but there is one that I always want to be set to true explicitly. 其中一些是由用户设置的,但我一直希望将其明确地设置为true。 How can I do that? 我怎样才能做到这一点? here is my Code: 这是我的代码:

@model Path.To.MyModels.BlanksVM @model Path.To.MyModels.BlanksVM

@using (Ajax.BeginForm("BodyMassIndex"
                        ,"Blanks"
                        , FormMethod.Get
                        , new AjaxOptions() { OnSuccess = "FillUpFields" }))
          {
            <table style="margin: 0px auto; margin-top: 10px;">
                <tbody>
                    <tr>
                        <td>
                            <span>Weight: </span>
                            @Html.TextBoxFor(m=>  m.FieldValues["bodyWeight"])
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span>Height: </span>
                            @Html.TextBoxFor(m => m.FieldValues["bodyHeight"])
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span>IBM: </span>
                            @Html.TextBoxFor(m => m.FieldValues["indexOfBodyMass"])
                        </td>                 
                </tbody>          
            </table>

            <div style="padding-top: 7px; padding-bottom: 7px;">
                <input type="submit" value="Calculate" style="padding: 3px;"/>
            </div>
         } 

Inside of the BlanksVM model I have a property called " MakeCalculations " and I am trying to always set it to true after submission. BlanksVM模型内部,我有一个名为“ MakeCalculations ”的属性,我试图在提交后始终将其设置为true。 Can you help me do that? 你能帮我吗?

@Html.HiddenFor(m => m.MakeCalculations, new { @Value = "true" })

If you have to do it in the form. 如果必须以表格形式进行。

But that is probably not the best way.. if it's always true then why do you need to set it? 但这可能不是最好的方法..如果始终都是如此,那为什么还要设置它呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM