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;
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">−</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
add a comment |
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">−</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
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
add a comment |
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">−</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
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">−</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
c# asp.net asp.net-mvc drop-down-menu
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
Please see my Updated Post
– microchef
Mar 25 at 18:54
add a comment |
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);
add a comment |
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.
no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine
– microchef
Mar 26 at 19:24
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Please see my Updated Post
– microchef
Mar 25 at 18:54
add a comment |
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
Please see my Updated Post
– microchef
Mar 25 at 18:54
add a comment |
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
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
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
add a comment |
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
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 27 at 17:59
microchefmicrochef
398 bronze badges
398 bronze badges
add a comment |
add a comment |
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.
no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine
– microchef
Mar 26 at 19:24
add a comment |
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.
no, because im using @model Assets.Areas.Clinical.Models.ClinicalAsset. all other fields post back just fine
– microchef
Mar 26 at 19:24
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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