How to save a dropdownlist selection back to the database - c#

My dropdown is pulling and displaying the correct list, however once selected, I click save and the selected option is disregarded and once again the value is empty.
//get
public ActionResult Edit(int id)
{
Prospect prospect = db.Prospects.Find(id);
if (prospect == null)
{
return HttpNotFound();
}
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", prospect.Product);
return View(prospect);
}
//post
[HttpPost]
public ActionResult Edit(Prospect prospect)
{
if (ModelState.IsValid)
{
db.Entry(prospect).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", prospect.Product);
return View(prospect);
}
//view
<div class="editor-label">
#Html.LabelFor(model => model.Product)
</div>
<div class="editor-field">
#Html.DropDownList("ProductId", String.Empty)
#Html.ValidationMessageFor(model => model.Product)
</div>
Any help will be greatly appreciated

only for helpers (except display) are tied to the model. change your drop down list to
#Html.DropDownListFor(x => x.ProductID, (SelectList)ViewBag.ProductID)
where ProductID is whatever value in your model you want the selected item tied to. You also set the drop down this way by setting that value before passing it to the view
Update:
I agree with Muffin Mans answer. Using ViewBag to send drop down lists to the view can be unreliable. A different way to put the answer the muffin man provided
Add an list to your model
public List<SelectListItem> Products { get; set; }
then on your controller populate that list from the database. Muffin Man provided one way to do it. We access our data differently so I populate my list with a foreach
var products = //populate the list from your database
List<SelectListItem> ls = new List<SelectListItem>();
foreach(var temp in products){
ls.Add(new SelectListItem() { Text = temp.ProductName, Value = temp.ProductID });
}
Model.Products = ls; // set the list in your model to the select list you just built
then on your view instead of casting a view bag list to a select list you can just reference the list from the model
#Html.DropDownListFor(x => x.ProductID, Model.Products)

You shouldn't be tying your view directly to your database table type. Use a view model. Additionally this type of data belongs in your view model, not the viewbag. The view bag is great for sharing things like page title between your view and the layout page.
public class ProspectViewModel
{
public IEnumerable<SelectListItem> ProspectList { get; set; }
[DisplayName("Product")] //This is for our label
public int SelectedProspectId { get; set; }
}
Get
public ActionResult Edit(int id)
{
var prospect = db.Prospects.Find(id);
if (prospect == null)
{
return HttpNotFound();
}
var model = new ProspectViewModel
{
ProductList = db.Products.Select(x=> new SelectListItem { ... })
};
return View(model);
}
Post
[HttpPost]
public ActionResult Edit(ProspectViewModel model)
{
if (ModelState.IsValid)
{
var prospect = new Prospect { /* populate with values from model */ };
db.Prospects.Attach(prospect);
db.Entry(prospect).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
//Need to repopulate drop down list
//And we don't need to set SelectedProductId because it's already been posted back
model.ProductList = db.Products.Select(x=> new SelectListItem { ... });
return View(model);
}
View
<div class="editor-label">
#Html.LabelFor(model => model.SelectedProductId)
</div>
<div class="editor-field">
#Html.DropDownListFor(x=> x.SelectedProductId, Model.ProductList)
#Html.ValidationMessageFor(x=> x.SelectedProductId)
</div>
This is outside the scope of this answer, but you shouldn't be doing data access within your controller. Microsoft's examples show this because they are meant to be "Hello world" examples, not necessarily to be taken literally.

Related

Storing data between requests in dbcontext

I have a page with server side rendering using razor, where you can add a couple of elements from different lists, fill some fields and create a request from it on submit.
Each time an item is added/taken from any list, I send a post with submit button to a specific action, e.g. "CustomerSelected". I do this, because I need to recreate additional view components for the added item. In these methods I would like to add added objects to the db context, so on submit I can just say SaveChanges() and not have to assemble everything in the same method. But in .net core db context is per request and it is advisable to keep it that way. In this case how can I store these temporary entity objects between requests so later if someone decides to submit them I can say SaveChanges() or discard them otherwise?
I would like to have something like this:
public IActionResult CustomerAdded(int customerId)
{
var customer = _context.Customers.First(c => c.IdCustomer == customerId);
var message = _context.Messages.First(m => m.IdMessage = _idMessage);
message.Customers.Add(customer);
return View();
}
public IActionResult ItemAdded(int itemId)
{
var item = _context.Items.First(c => c.IdItem == itemId);
var message = _context.Messages.First(m => m.IdMessage = _idMessage);
message.Items.Add(item);
return View();
}
public IActionResult Submit()
{
_context.SaveChanges();
return View();
}
If this is not possible then I was thinking about adding individual elements in each method and save them there and onsubmit I would build the last final element. But if someone closes their browser without submitting then I have incomplete data laying in my database. I would have to run some kind of job to delete those and it seems to be too much for such a simple task.
It's not good idea to use server resources to track changes in such scenarios. In scenarios like shopping basket, list or batch editing it's better track changes at client-side.
Your requirement to get Views generated at server-side doesn't mean you need to track changes in DbContext. Get the index view and create view from server, but track changes on client. Then to save, post all data to the server to save changes based on the tracking info that you have.
The mechanism for client-side change tracking depends to the requirement and the scenario, for example you can track changes using html inputs, you can track changes using cookie, you can track changes using javascript objects in browser memory like angular scenarios.
Here is this post I'll show an example using html inputs and model binding. To learn more about this topic, take a look at this article by Phill Haack: Model Binding To A List.
Example
In the following example I describe a list editing scenario for a list of customers. To make it simple, I suppose:
You have a list of customers which you are going to edit at client. You may want to add, edit or delete items.
When adding new item, the row template for new row should come from server.
When deleting, you mark an item as deleted by clicking on a checkbox on the row.
When adding/editing you want to show validation errors near the cells.
You want to save changes at the end, by click on Save button.
To implement above scenario Then you need to create following models, actions and views:
Trackable<T> Model
This class is a model which helps us in client side tracking and list editing:
public class Trackable<T>
{
public Trackable() { }
public Trackable(T model) { Model = model; }
public Guid Index { get; set; } = Guid.NewGuid();
public bool Deleted { get; set; }
public bool Added { get; set; }
public T Model { get; set; }
}
Customer Model
The customer model:
public class Customer
{
[Display(Name ="Id")]
public int Id { get; set; }
[StringLength(20, MinimumLength = 1)]
[Required]
[Display(Name ="First Name")]
public string FirstName { get; set; }
[StringLength(20, MinimumLength = 1)]
[Required]
[Display(Name ="Last Name")]
public string LastName { get; set; }
[EmailAddress]
[Required]
[Display(Name ="Email Name")]
public string Email { get; set; }
}
Index.cshtml View
The Index view is responsible to render List<Trackable<Customer>>. When rendering each record, we use RowTemplate view. The same view which we use when adding new item.
In this view, we have a submit button for save and a button for adding new rows which calls Create action using ajax.
Here is Index view:
#model IEnumerable<Trackable<Customer>>
<h2>Index</h2>
<form method="post" action="Index">
<p>
<button id="create">New Customer</button>
<input type="submit" value="Save All">
</p>
<table class="table" id="data">
<thead>
<tr>
<th>
Delete
</th>
<th>
#Html.DisplayNameFor(x => x.Model.FirstName)
</th>
<th>
#Html.DisplayNameFor(x => x.Model.LastName)
</th>
<th>
#Html.DisplayNameFor(x => x.Model.Email)
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
await Html.RenderPartialAsync("RowTemplate", item);
}
</tbody>
</table>
</form>
#section Scripts{
<script>
$(function () {
$('#create').click(function (e) {
e.preventDefault();
$.ajax({
url: 'Create',
method: 'Get',
success: function (data) {
$('#data tbody tr:last-child').after(data);
},
error: function (e) { alert(e); }
});
});
});
</script>
}
RowTemplate.cshtml View
This view is responsible to render a customer record. In this view, we first render the Index in a hidden, then set a prefix [index] for the fields and then render the fields, including index again, added, deleted and model id:
Here is RowTemplate View:
#model Trackable<Customer>
<tr>
<td>
#Html.HiddenFor(x => x.Index)
#{Html.ViewData.TemplateInfo.HtmlFieldPrefix = $"[{Model.Index}]";}
#Html.HiddenFor(x => x.Index)
#Html.HiddenFor(x => x.Model.Id)
#Html.HiddenFor(x => x.Added)
#Html.CheckBoxFor(x => x.Deleted)
</td>
<td>
#Html.EditorFor(x => x.Model.FirstName)
#Html.ValidationMessageFor(x => x.Model.FirstName)
</td>
<td>
#Html.EditorFor(x => x.Model.LastName)
#Html.ValidationMessageFor(x => x.Model.LastName)
</td>
<td>
#Html.EditorFor(x => x.Model.Email)
#Html.ValidationMessageFor(x => x.Model.Email)
</td>
</tr>
CustomerController
public class CustomerController : Controller
{
private static List<Customer> list;
}
It will have the following actions.
[GET] Index Action
In this action you can load data from database and shape it to a List<Trackable<Customer>> and pass to the Index View:
[HttpGet]
public IActionResult Index()
{
if (list == null)
{
list = Enumerable.Range(1, 5).Select(x => new Customer()
{
Id = x,
FirstName = $"A{x}",
LastName = $"B{x}",
Email = $"A{x}#B{x}.com"
}).ToList();
}
var model = list.Select(x => new Trackable<Customer>(x)).ToList();
return View(model);
}
[GET] Create Action
This action is responsible to returning new row template. It will be called by a button in Index View using ajax:
[HttpGet]
public IActionResult Create()
{
var model = new Trackable<Customer>(new Customer()) { Added = true };
return PartialView("RowTemplate", model);
}
[POST] Index Action
This action is responsible for receiving the tracked item from client and save them. The model which it receives is List<Trackable<Customer>>. It first strips the validation error messages for deleted rows. Then removes those which are both deleted and added. Then checks if model state is valid, tries to apply changes on data source.
Items having Deleted property as true are deleted, items having Added as true and Deleted as false are new items, and rest of items are edited. Then without needing to load all items from database, just using a for loop, call db.Entry for each item and set their states and finally save changes.
[HttpPost]
public IActionResult Index(List<Trackable<Customer>> model)
{
//Cleanup model errors for deleted rows
var deletedIndexes = model.
Where(x => x.Deleted).Select(x => $"[{x.Index}]");
var modelStateDeletedKeys = ModelState.Keys.
Where(x => deletedIndexes.Any(d => x.StartsWith(d)));
modelStateDeletedKeys.ToList().ForEach(x => ModelState.Remove(x));
//Removing rows which are added and deleted
model.RemoveAll(x => x.Deleted && x.Added);
//If model state is not valid, return view
if (!ModelState.IsValid)
return View(model);
//Deleted rows
model.Where(x => x.Deleted && !x.Added).ToList().ForEach(x =>
{
var i = list.FindIndex(c => c.Id == x.Model.Id);
if (i >= 0)
list.RemoveAt(i);
});
//Added rows
model.Where(x => !x.Deleted && x.Added).ToList().ForEach(x =>
{
list.Add(x.Model);
});
//Edited rows
model.Where(x => !x.Deleted && !x.Added).ToList().ForEach(x =>
{
var i = list.FindIndex(c => c.Id == x.Model.Id);
if (i >= 0)
list[i] = x.Model;
});
//Reditect to action index
return RedirectToAction("Index");
}
What about dynamic form(s) with javascript and using type="hidden" or visibility
and then sending everything at once
Or using TempData with redirects and reusing that data in other views(form) as input type="hidden"
Flow:
Form1 ->
Controller's Method saves data in TempData and Redirects to Form2 View / Or ViewData and return Form2 View? ->
Form2 has TempData inserted into the form under hidden inputs ->
Submit both at once
Cookie !
public class HomeController : Controller
{
public string Index()
{
HttpCookie cookie = Request.Cookies["message"];
Message message = null;
string json = "";
if (cookie == null)
{
message = new Message();
json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(message);
cookie = new HttpCookie("message", json);
}
Response.Cookies.Add(cookie);
return json;
}
public string CustomerAdded(int id)
{
HttpCookie cookie = Request.Cookies["message"];
Message message = null;
string json = "";
if (cookie == null || string.IsNullOrEmpty(cookie.Value))
{
message = new Message();
json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(message);
cookie = new HttpCookie("message", json);
}
else
{
json = cookie.Value;
message = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Message>(json);
}
if (message.Customers == null) message.Customers = new List<int>();
if (message.Items == null) message.Items = new List<int>();
if (!message.Customers.Contains(id))
{
message.Customers.Add(id);
}
json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(message);
cookie = new HttpCookie("message", json);
Response.Cookies.Add(cookie);
return json;
}
public string ItemAdded(int id)
{
HttpCookie cookie = Request.Cookies["message"];
Message message = null;
string json = "";
if (cookie == null || string.IsNullOrEmpty(cookie.Value))
{
message = new Message();
json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(message);
cookie = new HttpCookie("message", json);
}
else
{
json = cookie.Value;
message = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Message>(json);
}
if (message.Customers == null) message.Customers = new List<int>();
if (message.Items == null) message.Items = new List<int>();
if (!message.Items.Contains(id))
{
message.Items.Add(id);
}
json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(message);
cookie = new HttpCookie("message", json);
Response.Cookies.Add(cookie);
return json;
}
public string Submit()
{
HttpCookie cookie = Request.Cookies["message"];
Message message = null;
string json = "";
if (cookie == null || string.IsNullOrEmpty(cookie.Value))
{
return "no data";
}
else
{
json = cookie.Value;
message = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Message>(json);
}
Response.Cookies["message"].Value = "";
Response.Cookies["message"].Expires = DateTime.Now.AddDays(-1);
return "Submited";
}
}
Example links
http://localhost:58603/Home/CustomerAdded/1
http://localhost:58603/Home/CustomerAdded/2
http://localhost:58603/Home/Submit

Get selected values of a ListBox

Model:
public virtual ICollection<Product> OriginalProducts { get; set; }
public virtual ICollection<Product> SimilarProducts { get; set; }
View (Create and Edit are equal):
<div id="divSimilar" class="form-group">
#Html.Label("Similar Products", htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.ListBox("Products", null, htmlAttributes: new { #class = "form-control" })
</div>
</div>
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "MyAttributes")] Product product)
{
if (ModelState.IsValid)
{
db.Products.Add(product);
List<string> selectedSimilars = Request.Form.GetValues("Products").ToList();
foreach (string Id in selectedSimilars)
{
Product similarProd = db.Products.Find(System.Convert.ToInt32(Id));
if (similarProd != null)
product.SimilarProducts.Add(similarProd);
}
db.SaveChanges();
return RedirectToAction("Index").Success("Successfully created");
}
ViewBag.Products = new SelectList(db.Products, "Id", "Name", product.SimilarProducts);
return View(product);
}
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Product product = db.Products.Find(id);
if (product == null)
{
return HttpNotFound();
}
ViewBag.Products = new SelectList(db.Products.Where(p => p.Id != product.Id), "Id", "Name", product.SimilarProducts);
return View(product);
}
So, since "Create" part is working fine, I want to know how can I make to get all selected SimilarProducts (that I added in "Create") in my "Edit" view. What changes are necessary in controller to make it work?
Btw, since I'm using the ListBox, I think there's a different way of the DropDownList, because I used this way for all my DropDownLists and are working fine.
EDIT
I want to display in "Edit" view, all products (that were selected when I created that product) in blue. In other words, the ActionResult "Edit" should get all selected products from the SimilarProducts list, as in the DropDownList.
ListBox Control may have multiple selected Items (thus, multiple different values) as demonstrated in the following code snippet (re: https://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.selecteditems%28v=vs.110%29.aspx)
private void SelectedItems(object sender, RoutedEventArgs e)
{
if (lb.SelectedItem != null)
{
label1.Content = "Has " + (lb.SelectedItems.Count.ToString()) + " item(s) selected.";
}
}
You should specify the business logic for finding the Item in the selection (e.g., first in the selection). But, if selection mode is set to Single you may use the property SelectedItem.
Hope this may help.
Finally I managed to make it work, I'll post the solution, in case of anyone needs in the future:
ViewBag.Products = new MultiSelectList(db.Products.Where(p => p.Id != product.Id), "Id", "Name", product.SimilarProducts.Select(p => p.Id));
Little explanation:
Since I'm using ListBox, so I must use MultiSelectList, because SelectList recognizes just one item selected, its parameter is: (object selectedValue), already on MultiSelectList is: (IEnumerable selectedValues), so I changed SelectList to MultiSelectList and added it: .Select(p => p.Id)) into my ActionResult "Edit".

I have got trouble to send id from view to controler

#model IEnumerable<Evidencija.Models.Vozilo>
#{
ViewBag.Title = "PokreniIzvjestaj";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>PokreniIzvjestaj</h2>
#using (Html.BeginForm()) {
#Html.ValidationSummary(true)
<fieldset>
<legend>Vozilo</legend>
<p>
#Html.DropDownList("Vozila", Model.Select(p => new SelectListItem { Text = p.VoziloID.ToString(), Value = p.VoziloID.ToString() }), "Izaberi vozilo")
</p>
<input type="submit" value="Dodaj stavku" />
</fieldset>
}
I want to send id of table vozilo to controler with dropdownlist.
Controler accepts vozilo as a parameter but it is ollways zero.
How can I solve this without using viewmodel.
[HttpPost]
public ActionResult PokreniIzvjestaj(Vozilo v)
{
ReportClass rpt = new ReportClass();
rpt.FileName = Server.MapPath("~/Reports/Vozilo.rpt");
rpt.Load();
//ReportMethods.SetDBLogonForReport(rpt);
//ReportMethods.SetDBLogonForSubreports(rpt);
// rpt.VerifyDatabase();
rpt.SetParameterValue("#VoziloId",v.VoziloID);
Stream stream = null;
stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf", "Vozilo.pdf");
//PortableDocFormat--pdf format
//application/pdf -- vezan za pdf format, ako je drugi tip mjenja se u zavisnosti od izabranog
//naziv.pdf -- naziv dokumenta i izabrana ekstenzija
}
[HttpGet]
public ActionResult PokreniIzvjestaj()
{
var vozila = db.Voziloes.ToList();
return View(vozila);
}
There are two method from controler.
You currently binding your drop down to a property named Vozilo. A <select> post back single value (in your case the VoziloID or the selected option. Your POST method then tries to bind a complex object Vozilo to an int (assuming VoziloID is typeofint) which of course fails and the model isnull`. You could solve this changing the method to
[HttpPost]
public ActionResult PokreniIzvjestaj(int Vozilo)
The parameter Vozilo will now contain the value of the selected VoziloID.
However it not clear why you want to "solve this without using viewmodel" when using a view model is the correct approach
View model
public class VoziloVM
{
[Display(Name = "Vozilo")]
[Required(ErrorMessage = "Please select a Vozilo")]
public int? SelectedVozilo { get; set; }
public SelectList VoziloList { get; set; }
}
Controller
public ActionResult PokreniIzvjestaj()
{
var viziloList = db.Voziloes.Select(v => v.VoziloID);
VoziloVM model = new VoziloVM();
model.VoziloList = new SelectList(viziloList)
model.SelectedVozilo = // set a value here if you want a specific option selected
return View(model);
}
[HttpPost]
public ActionResult PokreniIzvjestaj(VoziloVM model)
{
// model.SelectedVozilo contains the value of the selected option
....
}
View
#model YourAssembly.VoziloVM>
....
#Html.LabelFor(m => m.SelectedVozilo)
#Html.DropDownListFor(m => m.SelectedVozilo, Model.VoziloList, "-Please select-")
#Html.ValidationMessageFor(m => m.SelectedVozilo)
....

not able to see the view after postback

Hi I have got a drop downlist that I am binding that one in controller I have got one button in view with that I am doing some validations that's working fine,
when I submit the button for validation check i am not able to get the view with error message. Instead of this I am getting error like this " The view 'PostValues' or its master was not found or no view engine supports the searched locations".
would any one help on why I am not able to get the view
here the view is strongly Typed view
and this is my code in controller.
public class CrossFieldsTxtboxesController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index()
{
var model = NewMethod();
return View(model);
}
private static CrossFieldValidation NewMethod()
{
var model = new CrossFieldValidation
{
SelectedValue = "Amount",
Items = new[]
{
new SelectListItem { Value = "Amount", Text = "Amount" },
new SelectListItem { Value = "Pound", Text = "Pound" },
new SelectListItem { Value = "Percent", Text = "Percent" },
}
};
return model;
}
[HttpPost]
public ActionResult PostValues(CrossFieldValidation model1)
{
model1 = NewMethod();
if (!ModelState.IsValid)
{
return View(model1);
}
else
{
return RedirectToAction("Index");
}
}
}
and this is my view
#model MvcSampleApplication.Models.CrossFieldValidation
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
#using (Html.BeginForm("PostValues", "CrossFieldsTxtboxes"))
{
#Html.ValidationSummary(true)
<div class ="editor-field">
#Html.TextBoxFor(m => m.TxtCrossField)
#Html.ValidationMessageFor(m=>m.TxtCrossField)
</div>
#Html.DropDownListFor(m=> m.SelectedValue , Model.Items)
<input id="PostValues" type="Submit" value="PostValues" />
}
would any one pls help on this...
This line
return View(model1);
looks for the view named exactly like the action in which it was called. Calling this line from PostValues action assumes there is a view PostValues.cshtml (which apparently does not exist). If you still want to use view Index - you should specify this explicitly:
if (!ModelState.IsValid)
{
return View("Index", model1);
}
As Andrei said. Alternatively, you can give your PostValues method an additional tag:
[HttpPost, ActionName("Index")]
public ActionResult PostValues(CrossFieldValidation model1)
{
if (!ModelState.IsValid)
{
return View(model1);
}
}

Selected DropDownList Value Not Sending to ASP.NET MVC Controller

I'm trying to pass the selected value of a DropDownList to a new controller method. However, in the controller, leagueKey is always coming back null. The drop down list is populating with values.
If I change new { leagueKey = Model.SelectedLeagueKey} to new {leagueKey = "test"} the controller correct receives the "test" value. It appears that the DropDownList isn't binding the selected value to Model.SelectedLeagueKey.
Model
public Dictionary<string, string> Leagues { get; set; }
public string SelectedLeagueKey { get; set; }
View
<div class="edit-field">
#Html.DropDownListFor(model => model.SelectedLeagueKey, new SelectList(Model.Leagues, "Key", "Value", Model.SelectedLeagueKey),"Select League")
</div>
#Html.ActionLink("Select League", "AddTeam", "Team", new { leagueKey = Model.SelectedLeagueKey}, null)
Controller
public ActionResult AddTeam(LTEDContext context, string leagueKey)
{
//Do something with leagueKey here
return View();
}
Your view send you the SelectedLeagueKey parameter according to
<div class="edit-field">
#Html.DropDownListFor(model => model.SelectedLeagueKey, new SelectList(Model.Leagues, "Key", "Value", Model.SelectedLeagueKey),"Select League")
</div>
Try to use the next code in a view:
#using (Html.BeginForm("AddTeam", "Team")) {
<div class="edit-field">
#Html.DropDownListFor(model => model.SelectedLeagueKey, new SelectList(Model.Leagues, "Key", "Value", Model.SelectedLeagueKey),"Select League")
</div>
<submit type="submit"/>
}
and the next one in controller:
public ActionResult AddTeam(LTEDContext context, string SelectedLeagueKey)
{
//Do something with leagueKey here
return View();
}

Categories