问题描述
Hii Everyone ..
我想将下拉列表中的select项目发送到asp.net mvc中的数据库。
我唯一的要求就是如何将下拉列表中的所有值{男性,女性}
保存到数据库中。
我是MVC的新手所以请建议我解决这个问题的简单方法
thnx提前
我尝试过:
这是查看
@ {var listItems = new List< SelectListItem>
{
new SelectListItem {Text =Select Your Gender,Value =1},
new SelectListItem {Text =Male,Value =2},
new SelectListItem {Text =Female,Value =3}
};
}
这是我的HomeController
public ActionResult Create(Student s)
{
示例dbContext = new Sample();
var v = dbContext.Students.Add(s);
dbContext.SaveChanges();
返回RedirectToAction(GetAllStudent);
}
Hii Everyone..
I want to send the select item from a drop down list to the database in asp.net mvc.
my only requirement is that how can all the values of drop down list {male, female}
will get save into the database.
I m new to MVC so please suggest me simple way to solve this issue
thnx in advance
What I have tried:
This is View
@{var listItems = new List<SelectListItem>
{
new SelectListItem {Text="Select Your Gender", Value="1"},
new SelectListItem {Text="Male", Value="2"},
new SelectListItem {Text="Female", Value="3"}
};
}
This is My HomeController
public ActionResult Create(Student s) { Sample dbContext = new Sample(); var v = dbContext.Students.Add(s); dbContext.SaveChanges(); return RedirectToAction("GetAllStudent"); }
这篇关于如何将选定的数据从下拉列表发送到ASP.NET MVC中的db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!