我将表格的一半移到一部分。 它包含了大部分的下拉列表。
列表值还可以,但是我没有在提交表单上检索所选数据。
我将局部模型传递到另一个模型中
public VMIdeaDescription ideaDescription = new VMIdeaDescription();
public class VMResource
{
public VMIdeaDescription ideaDescription = new VMIdeaDescription();
public List<EntityModality> Modalities { get; set; } = ServicesModality.ModalityGetAll();
public EntityModality Modality { get; set; }
public EntityIdeaModality CurrentIdeaModality { get; set; }
public List<EntityIdeaModality> IdeaModalities { get; set; } = new List<EntityIdeaModality>();}
我认为
@Html.Partial("_Description", Model.ideaDescription)
以及部分内部
<div class="col-sm-12">
<label>Language</label>
@Html.DropDownListFor(m => m.SelectedLanguage, Model.Languages.Select(x => new SelectListItem { Value = x.ToString(), Text = x.ToString() }), null, new { @class = "selectpicker" })
</div>
但是vm.ideaDescription.SelectedLanguage始终为空。
oyu可以帮我吗?
谢谢。
父模型:
public class VMResource
{
public List<EntityModality> Modalities { get; set; } = ServicesModality.ModalityGetAll();
public EntityModality Modality { get; set; }
public EntityIdeaModality CurrentIdeaModality { get; set; }
public List<EntityIdeaModality> IdeaModalities { get; set; } = new List<EntityIdeaModality>();
public string JsonObject { get; set; }
public dynamic CurrentJsonObject { get; set; }
public string ModalitiesData { get; set; }
public string GeneratedHtml { get; set; }
public int TemplateId { get; set; }
public List<EntityTemplate> Templates { get; set; } = ServicesTemplate.TemplateGetAll();
public Enums.StudioObjectType Type { get; set; } = Enums.StudioObjectType.Template;
public List<EntityList> Destinations { get; set; } = ServicesPMember.GetLists(Common.CurrentPMember.PMemberId);
public string SelectedDestination { get; set; } = "L";
public VMIdeaDescription IdeaDescription = new VMIdeaDescription();
}
Partiel模型
public class VMIdeaDescription
{
public Idea Idea { get; set; } = new Idea();
public List<EntityTag> Categories { get; set; } = ServicesProject.GetCategoryTree();
public List<string> SelectedCategory { get; set; }
public List<string> Languages { get; set; } = CfgVar.USE_LNG_FILTERING_AVAILABLE_LNG.Split(',').ToList();
public string SelectedLanguage { get; set; }
public List<EntityCompetency> Competencies { get; set; } = ServicesProject.GetCompetenciesTree(Common.CurrentProject.ProjectId);
public List<string> SelectedCompetency { get; set; }
public List<EntitySysTag> SystemTags { get; set; } = ServicesProject.GetSystemTags(Common.CurrentProject.ProjectId);
public List<EntityPMember> Authors { get; set; } = ServicesProject.GetMembers(Common.CurrentProject.ProjectId);
public List<int> SelectedAuthors { get; set; } = new List<int>();
public string Tags { get; set; }
public string SelectedSystemTag { get; set; }
public string Thumbnail { get; set; }
public bool AllowComment { get; set; } = true;
public bool Published { get; set; } = false;
}
控制器提交
[HttpPost]
[ValidateInput(false)]
public ActionResult AutoSaveResource(VMResource vm, string RadioDestinations)
{
//title or modality need to be setted to begin register
if (vm.ModalitiesData != null)
{
string title = vm.IdeaDescription.Idea.Title;
if (string.IsNullOrEmpty(title))
title = "My resource";
if (string.IsNullOrEmpty(vm.IdeaDescription.Idea.Content))
vm.IdeaDescription.Idea.Content = title;
//publish
if (vm.IdeaDescription.Published)
vm.SelectedDestination = "E";
else
vm.SelectedDestination = "L";
vm.IdeaDescription.Idea = Business.Idea.BusinessIdea.Save(vm.IdeaDescription.Idea.IdeaId > 0 ? vm.IdeaDescription.Idea : null, Common.CurrentProject.ProjectId, title, vm.IdeaDescription.Idea.Content,
"", false, false, "", false, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), Common.CurrentPMember.PMemberId.ToString(), "", vm.IdeaDescription.SelectedLanguage, null, (vm.SelectedDestination == "L" ? true : false), (vm.SelectedDestination == "G" || vm.SelectedDestination == "E" ? true : false), "", vm.IdeaDescription.SelectedCategory, vm.IdeaDescription.SelectedCompetency, vm.IdeaDescription.SelectedSystemTag, false, true, true,
null, false, "", null, false, null, null, false, 0, vm.IdeaDescription.AllowComment, true, "", false, vm.IdeaDescription.Published, vm.IdeaDescription.Tags);
if (!string.IsNullOrEmpty(vm.IdeaDescription.Thumbnail))
{
vm.IdeaDescription.Idea.Illustration = vm.IdeaDescription.Thumbnail.Trim();
vm.IdeaDescription.Idea.Update();
}
//save modality
if (vm.ModalitiesData != null)
{
EntityIdeaModality ideaModality = new EntityIdeaModality(vm.IdeaDescription.Idea.IdeaId, 0, vm.ModalitiesData, vm.GeneratedHtml, vm.TemplateId, Common.CurrentPMember.PMemberId);
ServicesModality.IdeaModalitySave(ideaModality);
vm.IdeaModalities = ServicesModality.IdeaModalityGetAll(vm.IdeaDescription.Idea.IdeaId).OrderByDescending(x => x.Id).ToList();
}
//create list if doesn't exist
string extId = string.Format(Constants.Destination_Studio_Resources, vm.IdeaDescription.Idea.IdeaId);
EntityList list = ServicesList.GetByExtId(Common.CurrentProject.ProjectId, extId);
if (list == null)
{
//create list
list = ServicesList.Create(Common.CurrentProject.ProjectId, Common.CurrentPMember.PMemberId, "Draft Idea " + vm.IdeaDescription.Idea.IdeaId, "", true);
list.ExtId = extId;
ServicesList.Save(list);
}
if (list != null)
{
//remove unselected pmember
List<EntityPMember> listPMembers = ServicesList.GetMembers(list.ListId);
foreach (EntityPMember listPMember in listPMembers)
{
ServicesList.RemovePMember(listPMember.PMemberId, list.ListId);
}
//add current PMemberId if not in
//if (!listPMembers.Any(x => x.PMemberId == Common.CurrentPMember.PMemberId))
ServicesList.AddPMember(Common.CurrentPMember.PMemberId, list.ListId);
//add selected authors
if (vm.IdeaDescription.SelectedAuthors.Count > 0)
{
foreach (int authorId in vm.IdeaDescription.SelectedAuthors)
{
if (authorId > 0 && authorId != Common.CurrentPMember.PMemberId)
ServicesList.AddPMember(authorId, list.ListId);
}
}
vm.IdeaDescription.Idea.AddDestination(list.ListId);
}
}
return Json(vm, JsonRequestBehavior.AllowGet);
}
vm.IdeaDescription内的所有内容均为null,除了已初始化的数据