Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.RadioButtonFor boolean

Ive got a form:

@using (Html.BeginForm("Buy", "Keys", FormMethod.Post))
{
<div class="calc_steps">
    <div class="NumberedRow one">
        1.  @Html.DropDownListFor(model => model.PaymentSystem, Model.PaymentSystems, new { @class = "calcsteps_select styledselect" })
    </div>
    <div class="NumberedRow two">
        2. <div class="cnt">
            Укажите тип лицензии
            <div class="radio-jquery-ui">@Html.RadioButtonFor(model => model.IsElite, "false") <label>Обычная</label></div>
            <div class="radio-jquery-ui">@Html.RadioButtonFor(model => model.IsElite, "true") <label>Расширенная</label></div>
           </div>
    </div>
    <div class="NumberedRow three">
        3.
        <div class="cnt">
             Введите срок
            @Html.TextBoxFor(model => model.NumDays)
        </div>
    </div>
    <div class="itog">
        Итого: <span id="ïtogo">0 рублей 00 копеек</span>
    </div>
    <div>
        <input type="submit" value="Купить"/>
    </div>
</div>
}

Model:

public class BuyModel
{
    public string PaymentSystem;
    public bool IsElite;
    public int NumDays;
    public IEnumerable<SelectListItem> PaymentSystems;
}

Action:

    [HttpPost]
    public ActionResult Buy(BuyModel model)
    {
        return View("BuySummary", model);
    }

And when I submit it the model.IsElite is always false(as by default). What am I doing wrong here?

like image 989
CodeDemen Avatar asked Mar 08 '13 04:03

CodeDemen


1 Answers

Replace

public bool IsElite;

with

public bool IsElite {get;set;}

It has to work now !

Remember to bind to the propertiesand not the variables

like image 197
Karthik Chintala Avatar answered Oct 03 '22 20:10

Karthik Chintala