VS'12 KendoUI InternetApplication Template C# asp.net EF Code First
我的问题是如何pass
将Regular
(现在正在传递)值和Ienumerable
(传递空值)都放入 mycontroller
并将它们保存到Databas
eEF Code First
在Many-2-Many Relationship
庄园中使用。
以下是我尝试过的
主视图
@model OG.Models.UserProfiles @using (Html.BeginForm()) { <div class="editor-field"> <div class="Containter"> <div> @Html.DisplayFor(model => model.UserName) </div> <div class="contentContainer"> @foreach (var item in Model.Prospects) { <table> <tr> <td> @Html.Label("Current Prospects") </td> </tr> <tr> <td> @Html.DisplayNameFor(x=>item.ProspectName) </td> </tr> </table> } </div> </div> <div class="contentContainer2"> @Html.Partial("_UsersInProspectsDDL", new OG.ModelView.ViewModelUserInProspects() { Users = Model.UserName }) </div> </div> }
局部视图
@model OG.ModelView.ViewModelUserInProspects <label for="prospects">Prospect:</label> @(Html.Kendo().DropDownListFor(m=>m.Prospects) .Name("Prospects") .HtmlAttributes(new { style = "width:300px"}) //, id = "countys"}) .OptionLabel("Select Prospect...") .DataTextField("ProspectName") .DataValueField("ProspectID") .DataSource(source => { source.Read(read => { read.Action("GetCascadeProspects", "ChangeUsersInfo") .Data("filterProspects"); }) .ServerFiltering(true); }) .Enable(false) .AutoBind(false) .CascadeFrom("Clients") </div>
局部视图模型
public class ViewModelUserInProspects { public string Clients { get; set; } public IEnumerable<dbClient> AvailableClients { get; set; } public string Prospects { get; set; } public IEnumerable<dbProspect> AvailableProspects { get; set; } public string Users { get; set; } public IEnumerable<UserProfiles> AvailableUsers {get;set;} } }
主要型号
Standart SimpleMemberShipUserTable
发布方法
[HttpPost] public ActionResult UsersInProspect( [Bind(Include= "ProspectName, ProspectID")] UserProfiles userprofiles, ViewModelUserInProspects values, FormCollection form) //<- Trying different things sofar { if (ModelState.IsValid) { //string something = form["Prospects"]; int prosID = Convert.ToInt16(values.Prospects); int UserID = userprofiles.UserID; // <- THIS VALUE is null atm.
这是我需要将两个 ID 保存到 EF 生成/映射表的地方。不确定如何。
db.Entry(userprofiles).CurrentValues.SetValues(userprofiles);
db.Entry(userprofiles).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(userprofiles);
}