在asp.net mvc中读取单选按钮的值

时间:2015-03-08 12:29:49

标签: c# jquery asp.net-mvc

任何人都可以告诉我如何从我的View中读取选中的单选按钮的值,并将此值保存在数据库属性type_of_user中。以下是该观点的一部分:

<div class="form-group">
    <div class="control-label col-md-2">
        Account Type: </div> 
        <div class="col-md-10">
            @Html.RadioButton("AccountType", "Individual", true) Individual
            @Html.RadioButton("AccountType", "Organization", false) Organization
            @Html.ValidationMessageFor(model => model.Type_of_user)

        </div>
    </div>

并在控制器中我放置了这段代码:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="Username,Password,Status,Email,Type_of_user,admin_id")] Account account)
{
    if (ModelState.IsValid)
    {
        db.Accounts.Add(account);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

    ViewBag.admin_id = new SelectList(db.Adminstrators, "Admin_ID", "Phone", account.admin_id);
    return View(account);
}

0 个答案:

没有答案