开发者

how to store value in database selected in dropdown list

this is my action of controller class

 public ActionResult checking()
        {
            rikuEntities db = new rikuEntities();
            IEnumerable<SelectListItem> items = db.emp.Select(c => new SelectListItem
            {
                Value = c.name,
                Text = c.name
            });
            ViewBag.saan = items;

            return View();

    }

Now i want to use this dropdownlist value in my UserCreate.cshtml. when i select a value from dropdownlist value开发者_如何学Pythons and press submit then that value should store in another table student. please suggest me what should i do for it ?


First of all you need to define your form:

using (Html.BeginForm()) 
{
     @HTML.DropDownList("SomeName", (SelectList)ViewBag.saan)
     <input type="submit" value="save" />
}

Then in your post controller:

[HttpPost]
public ActionResult checking(string SomeName)
{
   ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜