本文介绍了从users表中绑定下拉列表,然后将数据保存到捕获表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个小问题。我的问题是我正在使用MVC 4创建一个捕获表单并希望有一个下拉列表将用户绑定到它,然后它必须填充来自users表的表单加载,但是当我保存数据时它必须写入另一个表。 这是我的代码如下: @model CCICoaching.Models.Data_AgentCaochCapture @Model CCICoaching.Models.DropDownList @ { ViewBag.Title =创建; } 创建 @using(Html.BeginForm()){ @ Html.AntiForgeryToken() @ Html.ValidationSummary(true) Data_AgentCaochCapture Hi,I have a small problem. My problem is that I am making a capture form with MVC 4 and want a drop down list to bind the users to it, it must then populate on form load from the users table but when i save data it must then write to a different table.here is my code below:@model CCICoaching.Models.Data_AgentCaochCapture@Model CCICoaching.Models.DropDownList@{ ViewBag.Title = "Create";}Create@using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) Data_AgentCaochCapture @ Html.DropDownList(UserID,(IEnumerable< SelectListItem>)ViewBag.User) @Html.DropDownList("UserID", (IEnumerable<SelectListItem>)ViewBag.User) @ Html.LabelFor(model => model.UserName) @Html.LabelFor(model => model.UserName) @ Html.EditorFor(model => model.UserName) @ Html.ValidationMessageFor(model => model.UserName) @Html.EditorFor(model => model.UserName) @Html.ValidationMessageFor(model => model.UserName) @ Html.LabelFor(model => model.AgentName) @Html.LabelFor(model => model.AgentName) @ Html.EditorFor(model => model.AgentName) @ Html.ValidationMessageFor(model = > model.AgentName) @Html.EditorFor(model => model.AgentName) @Html.ValidationMessageFor(model => model.AgentName) @ Html.LabelFor(model => model.CaptureDate) @Html.LabelFor(model => model.CaptureDate) @ Html.EditorFor(model => model.CaptureDate) @ Html.ValidationMessageFor(model => model.CaptureDate) @Html.EditorFor(model => model.CaptureDate) @Html.ValidationMessageFor(model => model.CaptureDate) @ Html.LabelFor(model => model.RAG38Day) @Html.LabelFor(model => model.RAG38Day) @ Html.EditorFor(model => model.RAG38Day) @ Html.ValidationMessageFor(model => model.RAG38Day) @Html.EditorFor(model => model.RAG38Day) @Html.ValidationMessageFor(model => model.RAG38Day) @ Html.LabelFor(model => model.RAGBetterDeal) @Html.LabelFor(model => model.RAGBetterDeal) @ Html.EditorFor(model => model.RAGBetterDeal) @ Html.ValidationMessageFor(model = > model.RAGBetterDeal) @Html.EditorFor(model => model.RAGBetterDeal) @Html.ValidationMessageFor(model => model.RAGBetterDeal) @ Html.LabelFor(model => model.RAGTech) @Html.LabelFor(model => model.RAGTech) @ Html.EditorFor(model => model.RAGTech) @ Html.ValidationMessageFor(model => model.RAGTech) @Html.EditorFor(model => model.RAGTech) @Html.ValidationMessageFor(model => model.RAGTech) b $ b @ Html.LabelFor(model => model.RAGCSB) @Html.LabelFor(model => model.RAGCSB) @ Html.EditorFor(model => model.RAGCSB) @ Html.ValidationMessageFor(model => model.RAGCSB) @Html.EditorFor(model => model.RAGCSB) @Html.ValidationMessageFor(model => model.RAGCSB) @ Html.LabelFor(model => model.BrightStart) @Html.LabelFor(model => model.BrightStart) @ Html.EditorFor(model => model.BrightStart) @ Html.ValidationMessageFor(model = > model.BrightStart) @Html.EditorFor(model => model.BrightStart) @Html.ValidationMessageFor(model => model.BrightStart) @ Html.LabelFor(model => model.MakeConnection) @Html.LabelFor(model => model.MakeConnection) @ Html.EditorFor(model => model.MakeConnection) @ Html.ValidationMessageFor(model => model.MakeConnection) @Html.EditorFor(model => model.MakeConnection) @Html.ValidationMessageFor(model => model.MakeConnection) @ Html.LabelFor(model => model.IsolateAn dFix) @Html.LabelFor(model => model.IsolateAndFix) @ Html.EditorFor(model => model.IsolateAndFix) @ Html.ValidationMessageFor(model => model.IsolateAndFix) @Html.EditorFor(model => model.IsolateAndFix) @Html.ValidationMessageFor(model => model.IsolateAndFix) @ Html.LabelFor(model => model.AddValue) @Html.LabelFor(model => model.AddValue) @ Html.EditorFor(model => model.AddValue) @ Html.ValidationMessageFor(model = > model.AddValue) @Html.EditorFor(model => model.AddValue) @Html.ValidationMessageFor(model => model.AddValue) @ Html.LabelFor(model => model.BrightEnding) @Html.LabelFor(model => model.BrightEnding) @ Html.EditorFor(model => model.BrightEnding) @ Html.ValidationMessageFor(model => model.BrightEnding) @Html.EditorFor(model => model.BrightEnding) @Html.ValidationMessageFor(model => model.BrightEnding) @ Html.LabelFor(model => model.MetPreviou sObjective) @Html.LabelFor(model => model.MetPreviousObjective) @ Html.EditorFor(model => model.MetPreviousObjective) @ Html.ValidationMessageFor(model => model.MetPreviousObjective) @Html.EditorFor(model => model.MetPreviousObjective) @Html.ValidationMessageFor(model => model.MetPreviousObjective) @ Html.LabelFor(model => model.Goal) @Html.LabelFor(model => model.Goal) @ Html.EditorFor(model => model.Goal) @ Html.ValidationMessageFor(model = > model.Goal) @Html.EditorFor(model => model.Goal) @Html.ValidationMessageFor(model => model.Goal) @ Html.LabelFor(model => model.GoalType) @Html.LabelFor(model => model.GoalType) @ Html.EditorFor(model => model.GoalType) @ Html.ValidationMessageFor(model => model.GoalType) @Html.EditorFor(model => model.GoalType) @Html.ValidationMessageFor(model => model.GoalType) @ Html.LabelFor(model => model.Reality) @Html.LabelFor(model => model.Reality) @ Html.EditorFor(model => model.Reality) @ Html.ValidationMessageFor(model => model.Reality) @Html.EditorFor(model => model.Reality) @Html.ValidationMessageFor(model => model.Reality) @ Html.LabelFor(model => model.Options) @Html.LabelFor(model => model.Options) @ Html.EditorFor(model => model.Options) @ Html.ValidationMessageFor(model = > model.Options) @Html.EditorFor(model => model.Options) @Html.ValidationMessageFor(model => model.Options) @ Html.LabelFor(model => model.WillOrWayForward) @Html.LabelFor(model => model.WillOrWayForward) @ Html.EditorFor(model => model.WillOrWayForward) @ Html.ValidationMessageFor(model => model.WillOrWayForward) @Html.EditorFor(model => model.WillOrWayForward) @Html.ValidationMessageFor(model => model.WillOrWayForward) @ Html.LabelFor(model => model.Rebuttal) @Html.LabelFor(model => model.Rebuttal) @ Html.EditorFor(model => model.Rebuttal) @ Html.ValidationMessageFor(model => model.Rebuttal) @Html.EditorFor(model => model.Rebuttal) @Html.ValidationMessageFor(model => model.Rebuttal) @ Html.LabelFor(model => model.CF) @Html.LabelFor(model => model.CF) @ Html.EditorFor(model => model.CF) @ Html.ValidationMessageFor(model = > model.CF) @Html.EditorFor(model => model.CF) @Html.ValidationMessageFor(model => model.CF) @ Html.LabelFor(model => model.UnexplainedSilence) @Html.LabelFor(model => model.UnexplainedSilence) @ Html.EditorFor(model => model.UnexplainedSilence) @ Html.ValidationMessageFor(model => model.UnexplainedSilence) @Html.EditorFor(model => model.UnexplainedSilence) @Html.ValidationMessageFor(model => model.UnexplainedSilence) @ Html.LabelFor(model => model.CorrectHoldProcess) @Html.LabelFor(model => model.CorrectHoldProcess) @ Html.EditorFor(model => model.CorrectHoldProcess) @ Html.ValidationMessageFor(model => model.CorrectHoldProcess) @Html.EditorFor(model => model.CorrectHoldProcess) @Html.ValidationMessageFor(model => model.CorrectHoldProcess) @ Html.LabelFor(model => model.IncorrectNotes) @Html.LabelFor(model => model.IncorrectNotes) @ Html.EditorFor(model => model.IncorrectNotes) @ Html.ValidationMessageFor(model = > model.IncorrectNotes) @Html.EditorFor(model => model.IncorrectNotes) @Html.ValidationMessageFor(model => model.IncorrectNotes) @ Html.LabelFor(model => model.Incorrectransfer) @Html.LabelFor(model => model.Incorrectransfer) @Html.EditorFor(model => model.Incorrectransfer) @ Html.ValidationMessageFor(model => model.Incorrectransfer) @Html.EditorFor(model => model.Incorrectransfer) @Html.ValidationMessageFor(model => model.Incorrectransfer) @Ht ml.LabelFor(model => model.GoodCall) @Html.LabelFor(model => model.GoodCall) @ Html.EditorFor(model => ; model.GoodCall) @ Html.ValidationMessageFor(model => model.GoodCall) @Html.EditorFor(model => model.GoodCall) @Html.ValidationMessageFor(model => model.GoodCall) @ Html.LabelFor(model => model.CallAvoidance) @Html.LabelFor(model => model.CallAvoidance) @ Html.EditorFor(model => model.CallAvoidance) @ Html.ValidationMessageFor(model => model.CallAvoidance) @Html.EditorFor(model => model.CallAvoidance) @Html.ValidationMessageFor(model => model.CallAvoidance) @ Html.LabelFor(model => model.TVQAsked) @Html.LabelFor(model => model.TVQAsked) @ Html.EditorFor(model => model.TVQAsked) @ Html.ValidationMessageFor(model => model.TVQAsked) @Html.EditorFor(model => model.TVQAsked) @Html.ValidationMessageFor(model => model.TVQAsked) @ Html.LabelFor(model => model.CreditsOffered) @Html.LabelFor(model => model.CreditsOffered) @ Html.EditorFor(model => ; model.CreditsOffered) @ Html.ValidationMessageFor(model => model.CreditsOffered) @Html.EditorFor(model => model.CreditsOffered) @Html.ValidationMessageFor(model => model.CreditsOffered) @ Html.LabelFor(model => model.WeeklyCoachPlanFollowed) @Html.LabelFor(model => model.WeeklyCoachPlanFollowed) @ Html.EditorFor(model => model.WeeklyCoachPlanFollowed) @ Html.ValidationMessageFor(model => model.WeeklyCoachPlanFollowed) @Html.EditorFor(model => model.WeeklyCoachPlanFollowed) @Html.ValidationMessageFor(model => model.WeeklyCoachPlanFollowed) @ Html.LabelFor(model => model.OTDStartOfWeek) @Html.LabelFor(model => model.OTDStartOfWeek) @ Html.EditorFor(model => model.OTDStartOfWeek) @ Html.Validat ionMessageFor(model => model.OTDStartOfWeek) @Html.EditorFor(model => model.OTDStartOfWeek) @Html.ValidationMessageFor(model => model.OTDStartOfWeek) @ Html.LabelFor(model => model.OTDEndOfWeek) @Html.LabelFor(model => model.OTDEndOfWeek) @ Html.EditorFor(model => model.OTDEndOfWeek) @ Html.ValidationMessageFor(model => model.OTDEndOfWeek) @Html.EditorFor(model => model.OTDEndOfWeek) @Html.ValidationMessageFor(model => model.OTDEndOfWeek) @ Html.LabelFor(model => model.RAG) @Html.LabelFor(model => model.RAG) @ Html.EditorFor(model => model.RAG) @ Html.ValidationMessageFor(model => model.RAG) @Html.EditorFor(model => model.RAG) @Html.ValidationMessageFor(model => model.RAG) @ Html.LabelFor(model => model.CoachPlanFollowed) @Html.LabelFor(model => model.CoachPlanFollowed) @ Html.EditorFor(model => model.CoachPlanFollowed) @ Html.ValidationMessageFor(model => model.CoachPlanFollowed) @Html.EditorFor(model => model.CoachPlanFollowed) @Html.ValidationMessageFor(model => model.CoachPlanFollowed) @ Html.LabelFor(model => model.NextSteps) @Html.LabelFor(model => model.NextSteps) @ Html.EditorFor(model => model.NextSteps) @ Html.ValidationMessageFor(model = > model.NextSteps) @Html.EditorFor(model => model.NextSteps) @Html.ValidationMessageFor(model => model.NextSteps) @ Html.LabelFor(model => model.Notes) @Html.LabelFor(model => model.Notes) @ Html.EditorFor(model => model.Notes) @ Html.ValidationMessageFor(model => model.Notes) @Html.EditorFor(model => model.Notes) @Html.ValidationMessageFor(model => model.Notes) < input type =submitvalue =创建/> <input type="submit" value="Create" /> @ Html.ActionLink(返回列表, 索引) @Html.ActionLink("Back to List", "Index") @section脚本{ @ Scripts.Render( 〜/ bundles / jqueryval) } @section Scripts { @Scripts.Render("~/bundles/jqueryval")}推荐答案 访问此页面。这是你的直接解决方案: MVC4 Bind DropDown Visit this page. This is direct solution you your case:MVC4 Bind DropDown 这篇关于从users表中绑定下拉列表,然后将数据保存到捕获表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-01 08:41