Asp.net MVC multiple fields in dropdown list failing to postback to databaseCan an ASP.NET MVC controller return an Image?Compile Views in ASP.NET MVCHow do you create a dropdownlist from an enum in ASP.NET MVC?How do you handle multiple submit buttons in ASP.NET MVC Framework?How to render an ASP.NET MVC view as a string?How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?ASP.NET MVC - Set custom IIdentity or IPrincipalGetting full URL of action in ASP.NET MVCFile Upload ASP.NET MVC 3.0Login failed for user 'IIS APPPOOLASP.NET v4.0'

Will greasing clutch parts make it softer

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

Which high-degree derivatives play an essential role?

Is it possible to obtain the address of the 'this' pointer?

Contributing to a candidate as a Foreign National US Resident?

Should I warn my boss I might take sick leave

Does this circuit have marginal voltage level problem?

If a creature is blocking and it has vigilance does it still tap?

Why did moving the mouse cursor cause Windows 95 to run more quickly?

When you're given a degree sequence, what is the method to draw a graph which has that degree sequence?

Does this house rule, for determining hit point maximum, make characters weaker than RAW?

Why are symbols not written in words?

Finding integer database columns that may have their data type changed to reduce size

Did Snape really give Umbridge a fake Veritaserum potion that Harry later pretended to drink?

Are there advantages in writing by hand over typing out a story?

Olive oil in Japanese cooking

When should we use dependency injection (C#)

Do I need to be legally qualified to install a Hive smart thermostat?

List of Implementations for common OR problems

How to compute the number of centroids for K-means clustering algorithm given minimal distance?

Show that there are infinitely more problems than we will ever be able to compute

Can I deep fry food in butter instead of vegetable oil?

What does the ash content of broken wheat really mean?

My mother co-signed for my car. Can she take it away from me if I am the one making car payments?



Asp.net MVC multiple fields in dropdown list failing to postback to database


Can an ASP.NET MVC controller return an Image?Compile Views in ASP.NET MVCHow do you create a dropdownlist from an enum in ASP.NET MVC?How do you handle multiple submit buttons in ASP.NET MVC Framework?How to render an ASP.NET MVC view as a string?How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?ASP.NET MVC - Set custom IIdentity or IPrincipalGetting full URL of action in ASP.NET MVCFile Upload ASP.NET MVC 3.0Login failed for user 'IIS APPPOOLASP.NET v4.0'






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a dropdown list that shows the Code & BudgetCodename of db.Budgets from the database.



the view snippet looks like this:



 @using (Html.BeginForm())

@Html.AntiForgeryToken()


<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
<a href="" class="minimize">&minus;</a>
</div>
<h4 class="panel-title">Block Styled Form</h4>
<p>This is an example of form with block styled label.</p>
</div>
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
@Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
</div>




and the controller looks like this:



 public ActionResult Create()



var Budgets = (from m in db.BudgetCodes
select new SelectListItem
Text = m.Code + ");

ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");





The drop down menu looks fine, and shows both thE Code and BudgetCodeName.



But the box does not post back the data to the sql Database. No errors are created.



What could I have done wrong ?



****Edit****



I have tried placing the controller text as such, but it doesn't work:



 [HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate,BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
await db.SaveChangesAsync();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);



****Update****



I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
db.SaveChanges();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);


``````









share|improve this question
























  • when you submit the form, is the action hit? can you put a debug breakpoint in your POST Create action to verify?

    – NeedleInAFullStack
    Mar 25 at 19:07











  • @johnluke.laue I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?

    – microchef
    Mar 26 at 19:42


















1















I have a dropdown list that shows the Code & BudgetCodename of db.Budgets from the database.



the view snippet looks like this:



 @using (Html.BeginForm())

@Html.AntiForgeryToken()


<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
<a href="" class="minimize">&minus;</a>
</div>
<h4 class="panel-title">Block Styled Form</h4>
<p>This is an example of form with block styled label.</p>
</div>
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
@Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
</div>




and the controller looks like this:



 public ActionResult Create()



var Budgets = (from m in db.BudgetCodes
select new SelectListItem
Text = m.Code + ");

ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");





The drop down menu looks fine, and shows both thE Code and BudgetCodeName.



But the box does not post back the data to the sql Database. No errors are created.



What could I have done wrong ?



****Edit****



I have tried placing the controller text as such, but it doesn't work:



 [HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate,BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
await db.SaveChangesAsync();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);



****Update****



I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
db.SaveChanges();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);


``````









share|improve this question
























  • when you submit the form, is the action hit? can you put a debug breakpoint in your POST Create action to verify?

    – NeedleInAFullStack
    Mar 25 at 19:07











  • @johnluke.laue I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?

    – microchef
    Mar 26 at 19:42














1












1








1








I have a dropdown list that shows the Code & BudgetCodename of db.Budgets from the database.



the view snippet looks like this:



 @using (Html.BeginForm())

@Html.AntiForgeryToken()


<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
<a href="" class="minimize">&minus;</a>
</div>
<h4 class="panel-title">Block Styled Form</h4>
<p>This is an example of form with block styled label.</p>
</div>
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
@Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
</div>




and the controller looks like this:



 public ActionResult Create()



var Budgets = (from m in db.BudgetCodes
select new SelectListItem
Text = m.Code + ");

ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");





The drop down menu looks fine, and shows both thE Code and BudgetCodeName.



But the box does not post back the data to the sql Database. No errors are created.



What could I have done wrong ?



****Edit****



I have tried placing the controller text as such, but it doesn't work:



 [HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate,BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
await db.SaveChangesAsync();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);



****Update****



I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
db.SaveChanges();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);


``````









share|improve this question
















I have a dropdown list that shows the Code & BudgetCodename of db.Budgets from the database.



the view snippet looks like this:



 @using (Html.BeginForm())

@Html.AntiForgeryToken()


<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
<a href="" class="minimize">&minus;</a>
</div>
<h4 class="panel-title">Block Styled Form</h4>
<p>This is an example of form with block styled label.</p>
</div>
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
@Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
</div>




and the controller looks like this:



 public ActionResult Create()



var Budgets = (from m in db.BudgetCodes
select new SelectListItem
Text = m.Code + ");

ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");





The drop down menu looks fine, and shows both thE Code and BudgetCodeName.



But the box does not post back the data to the sql Database. No errors are created.



What could I have done wrong ?



****Edit****



I have tried placing the controller text as such, but it doesn't work:



 [HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate,BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
await db.SaveChangesAsync();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);



****Update****



I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
db.SaveChanges();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);


``````






c# asp.net asp.net-mvc drop-down-menu






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 19:41







microchef

















asked Mar 25 at 18:10









microchefmicrochef

398 bronze badges




398 bronze badges












  • when you submit the form, is the action hit? can you put a debug breakpoint in your POST Create action to verify?

    – NeedleInAFullStack
    Mar 25 at 19:07











  • @johnluke.laue I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?

    – microchef
    Mar 26 at 19:42


















  • when you submit the form, is the action hit? can you put a debug breakpoint in your POST Create action to verify?

    – NeedleInAFullStack
    Mar 25 at 19:07











  • @johnluke.laue I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?

    – microchef
    Mar 26 at 19:42

















when you submit the form, is the action hit? can you put a debug breakpoint in your POST Create action to verify?

– NeedleInAFullStack
Mar 25 at 19:07





when you submit the form, is the action hit? can you put a debug breakpoint in your POST Create action to verify?

– NeedleInAFullStack
Mar 25 at 19:07













@johnluke.laue I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?

– microchef
Mar 26 at 19:42






@johnluke.laue I have found that removing the async from the controller does post back the integer to the table. How do I then make it work with async ? or is it worth dropping async altogether if i don't expect heavy loads or bandwidth issues because of a small user base ?

– microchef
Mar 26 at 19:42













3 Answers
3






active

oldest

votes


















1














You need to wrap the data you want to POST into a form:



@using (Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)) 
<div class="form-group">
@Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
@Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
</div>



Your POST action needs to accept the model you are posting:



public ActionResult Post(MyModel model)

//call a service to save info to database






share|improve this answer























  • Please see my Updated Post

    – microchef
    Mar 25 at 18:54


















1














I have found that removing the async from the controller does post back the integer to the table.



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

if (ModelState.IsValid)

db.ClinicalAssets.Add(clinicalAsset);
db.SaveChanges();
return RedirectToAction("Index");

ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem

Text = m.Code + " );
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);







share|improve this answer






























    0














    In your code. The data you are sending in a action method is of type POST.



     [HttpPost]


    [ValidateAntiForgeryToken]
    public async Task Create()



    You have to define the "FormMethod" in your view page. For example:



    @using (Html.BeginForm("ActionMethod Name", "Controller Name", FormMethod.Post))




    `
    I hope this my help.






    share|improve this answer























    • no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

      – microchef
      Mar 26 at 19:24














    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344086%2fasp-net-mvc-multiple-fields-in-dropdown-list-failing-to-postback-to-database%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You need to wrap the data you want to POST into a form:



    @using (Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)) 
    <div class="form-group">
    @Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
    @Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
    </div>



    Your POST action needs to accept the model you are posting:



    public ActionResult Post(MyModel model)

    //call a service to save info to database






    share|improve this answer























    • Please see my Updated Post

      – microchef
      Mar 25 at 18:54















    1














    You need to wrap the data you want to POST into a form:



    @using (Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)) 
    <div class="form-group">
    @Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
    @Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
    </div>



    Your POST action needs to accept the model you are posting:



    public ActionResult Post(MyModel model)

    //call a service to save info to database






    share|improve this answer























    • Please see my Updated Post

      – microchef
      Mar 25 at 18:54













    1












    1








    1







    You need to wrap the data you want to POST into a form:



    @using (Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)) 
    <div class="form-group">
    @Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
    @Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
    </div>



    Your POST action needs to accept the model you are posting:



    public ActionResult Post(MyModel model)

    //call a service to save info to database






    share|improve this answer













    You need to wrap the data you want to POST into a form:



    @using (Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)) 
    <div class="form-group">
    @Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new @class = "control-label" )
    @Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BudgetCodeID, "", new @class = "text-danger" )
    </div>



    Your POST action needs to accept the model you are posting:



    public ActionResult Post(MyModel model)

    //call a service to save info to database







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 25 at 18:35









    NeedleInAFullStackNeedleInAFullStack

    1,5352 gold badges9 silver badges40 bronze badges




    1,5352 gold badges9 silver badges40 bronze badges












    • Please see my Updated Post

      – microchef
      Mar 25 at 18:54

















    • Please see my Updated Post

      – microchef
      Mar 25 at 18:54
















    Please see my Updated Post

    – microchef
    Mar 25 at 18:54





    Please see my Updated Post

    – microchef
    Mar 25 at 18:54













    1














    I have found that removing the async from the controller does post back the integer to the table.



    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

    if (ModelState.IsValid)

    db.ClinicalAssets.Add(clinicalAsset);
    db.SaveChanges();
    return RedirectToAction("Index");

    ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
    ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
    ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
    ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
    ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
    ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
    ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
    ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
    var Budgets = (from m in db.BudgetCodes
    select new SelectListItem

    Text = m.Code + " );
    ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
    return View(clinicalAsset);







    share|improve this answer



























      1














      I have found that removing the async from the controller does post back the integer to the table.



      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

      if (ModelState.IsValid)

      db.ClinicalAssets.Add(clinicalAsset);
      db.SaveChanges();
      return RedirectToAction("Index");

      ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
      ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
      ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
      ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
      ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
      ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
      ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
      ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
      var Budgets = (from m in db.BudgetCodes
      select new SelectListItem

      Text = m.Code + " );
      ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
      return View(clinicalAsset);







      share|improve this answer

























        1












        1








        1







        I have found that removing the async from the controller does post back the integer to the table.



        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

        if (ModelState.IsValid)

        db.ClinicalAssets.Add(clinicalAsset);
        db.SaveChanges();
        return RedirectToAction("Index");

        ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
        ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
        ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
        ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
        ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
        ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
        ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
        ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
        var Budgets = (from m in db.BudgetCodes
        select new SelectListItem

        Text = m.Code + " );
        ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
        return View(clinicalAsset);







        share|improve this answer













        I have found that removing the async from the controller does post back the integer to the table.



        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)

        if (ModelState.IsValid)

        db.ClinicalAssets.Add(clinicalAsset);
        db.SaveChanges();
        return RedirectToAction("Index");

        ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
        ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
        ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
        ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
        ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
        ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
        ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
        ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
        var Budgets = (from m in db.BudgetCodes
        select new SelectListItem

        Text = m.Code + " );
        ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
        return View(clinicalAsset);








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 17:59









        microchefmicrochef

        398 bronze badges




        398 bronze badges





















            0














            In your code. The data you are sending in a action method is of type POST.



             [HttpPost]


            [ValidateAntiForgeryToken]
            public async Task Create()



            You have to define the "FormMethod" in your view page. For example:



            @using (Html.BeginForm("ActionMethod Name", "Controller Name", FormMethod.Post))




            `
            I hope this my help.






            share|improve this answer























            • no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

              – microchef
              Mar 26 at 19:24
















            0














            In your code. The data you are sending in a action method is of type POST.



             [HttpPost]


            [ValidateAntiForgeryToken]
            public async Task Create()



            You have to define the "FormMethod" in your view page. For example:



            @using (Html.BeginForm("ActionMethod Name", "Controller Name", FormMethod.Post))




            `
            I hope this my help.






            share|improve this answer























            • no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

              – microchef
              Mar 26 at 19:24














            0












            0








            0







            In your code. The data you are sending in a action method is of type POST.



             [HttpPost]


            [ValidateAntiForgeryToken]
            public async Task Create()



            You have to define the "FormMethod" in your view page. For example:



            @using (Html.BeginForm("ActionMethod Name", "Controller Name", FormMethod.Post))




            `
            I hope this my help.






            share|improve this answer













            In your code. The data you are sending in a action method is of type POST.



             [HttpPost]


            [ValidateAntiForgeryToken]
            public async Task Create()



            You have to define the "FormMethod" in your view page. For example:



            @using (Html.BeginForm("ActionMethod Name", "Controller Name", FormMethod.Post))




            `
            I hope this my help.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 10:51









            Parvesh YadavParvesh Yadav

            264 bronze badges




            264 bronze badges












            • no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

              – microchef
              Mar 26 at 19:24


















            • no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

              – microchef
              Mar 26 at 19:24

















            no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

            – microchef
            Mar 26 at 19:24






            no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine

            – microchef
            Mar 26 at 19:24


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344086%2fasp-net-mvc-multiple-fields-in-dropdown-list-failing-to-postback-to-database%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현