嗨,伙计们,我有两张看起来像这样的桌子
usertable RoleTable
----------------------- ---------------------------
UserID|UserName|Pwd|RoleID RoleID|RoleName
1 |Anil |123|1 1 |Admin
现在我在表格中显示用户表,他有一个 AddNew 链接,当管理员单击 AddNew 链接时,我将向他显示 AddNew 页面,其中他有一些标签和文本框给 AddNew 用户,
现在我要做的是在 AddNew 页面中我想在 DropDown 中显示所有 RoleNames,以便管理员可以选择用户必须是哪个角色....并且我想检索选定的数据
这是我的模型课
public class ResourceModel
{
public static List<ResourceModel> GetList { get; set; }
public Int16 EmployeeId { get; set; }
public string EmployeeName { get; set; }
public string EmployeeEmailId { get; set;}
public string GroupName { get; set; }
public string EmployeePassword { get; set; }
}
这是我的控制器
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult AddNew()
{
ViewBag.Roles = new SelectList(GetRoles(),"RoleID","RoleName");
return View();
}
//
//Geting All Roles In a GetRoles()/
//
public static GetRoles()
{
SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True");
SqlCommand Cmd = new SqlCommand("Select GroupId,EmplopyeeRole from EmployeeGroup", conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
//roles.Add(new SelectListItem{.Value=i,.Text=i};
var model = new ResourceModel();
model.RoleId = Convert.ToInt16(ds.Tables[0].Rows[i]["GroupId"]);
model.RoleName = ds.Tables[0].Rows[i]["EmplopyeeRole"].ToString();
//roles.Value=Convert.ToString( model.RoleId);
//roles.Text=model.RoleName;
}
conn.Close();
return ds ;
}
我必须在上面的代码中返回什么
这是我的 AddNew Aspx 页面
<div>
<% using (Html.BeginForm())
{ %>
<%-- <form action="Create.aspx" method="post"></form>--%>
<%:Html.ValidationSummary(true)%>
<fieldset>
<legend style="color:Orange; font-weight:bolder;">AddNew Project</legend>
<div class="editor-label" style="color:Orange; font-weight:bolder;">
<%: Html.LabelFor(model => model.EmployeeName)%>
</div>
<div class="editor-field">
<%:Html.EditorFor(model => model.EmployeeName)%>
<%: Html.ValidationMessageFor(model => model.EmployeeName)%>
</div>
<div class="editor-label" style="color:Orange; font-weight:bolder;">
<%:Html.LabelFor(model => model.EmployeeEmailId)%>
</div>
<div class="editor-field">
<%:Html.EditorFor(model => model.EmployeeEmailId)%>
<%:Html.ValidationMessageFor(model => model.EmployeeEmailId)%>
</div>
<div class="editor-label" style="color:Orange; font-weight:bolder;">
<%:Html.LabelFor(model => model.EmployeePassword)%>
</div>
<div class="editor-field">
<%:Html.EditorFor(model => model.EmployeePassword)%>
<%:Html.ValidationMessageFor(model => model.EmployeePassword)%>
</div>
<div class="editor-label" style="color:Orange; font-weight:bolder;">
<%:Html.LabelFor(model => model.GroupName)%>
</div>
<div class="editor-field">
<%:Html.EditorFor(model => model.GroupName)%>
<%:Html.ValidationMessageFor(model => model.GroupName)%>
<p>
<input type="submit" value="Create" style="color:Orange; font-weight:bolder;"/>
</p>
</fieldset>
<%} %>
</div>
任何人都可以帮助我在 MVC3 中执行此操作....我必须在下拉菜单中显示 RoleNames 我必须检索在控制器中的 [AcceptVerbs(HttpVerbs.Post)] 中选择的值....请有任何想法
我有一个我的 [AcceptVerbs(HttpVerbs.Post)] 的存储过程,其中使用选定的下拉值我将在 Db 中插入 RoleName 的 RoleID
Create Procedure InsertEmplyoee
(
@EmployeeName varchar(50),
@EmployeeEmailId varchar(50),
@EmployeePassword varchar (50),
@GroupName varchar (50)
)
as
begin
insert into EmployeeDetails (EmployeeName,EmployeeEmailId,EmployeePassword,GroupId) values
(@EmployeeName,@EmployeeEmailId,@EmployeePassword,(select GroupId from EmployeeGroup where EmplopyeeRole=@GroupName ))
结束