2013-03-08 6 views
6

アイブ氏は、フォームを得た:@ Html.RadioButtonForブール

@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> 
} 

モデル:

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

処置:

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

そして、私はそれを送信したときmodel.IsEliteは常に偽であります(デフォルトでは)。私はここで間違って何をしていますか?

+0

は完璧に見えるpropertiesに結合していないことを忘れないでください。それはいつもsux。私はそれがうまくいると思うが、あなたのモデルと行動の方法を共有する。 –

+0

Iveが自分の投稿を更新しました。あなたの時間をありがとう! – CodeDemen

+1

あなたは変数ではなくプロパティにバインドする必要があります –

答えて

1

のようにしてみてくださいその

public bool IsElite{get;set;}; 

のプロパティを設定する必要があります!

は変数

+1

Omg!ありがとうございました!私はMvcですでに十分な時間をコーディングしていて、このような間違いをしたことはありません...たぶん、寝る時間があります.O – CodeDemen

0

このようです。 ? あなたはそれが今で動作するように持って

public bool IsElite {get;set;} 

public bool IsElite; 

を交換し、この

@Html.RadioButtonFor(model => model.IsElite, "True", model.IsElite== true ? new { Checked = "checked" } : null) 
+0

いいえ、私は常に "False"の値を持つモデルを投稿することを意味します – CodeDemen