简体   繁体   中英

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. Some of them get set by the user but there is one that I always want to be set to true explicitly. How can I do that? here is my Code:

@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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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