I have problem with passing parameter in controller.
I get id value in public ActionResult AddIngridient(int id = 0) and i need to pass it in public ActionResult AddIngridient(Ingredients ingridients) like IngredientID. How to do this?
I have model:
public partial class Ingredients
{
public int IngredientID { get; set; }
public Nullable<int> AmountID { get; set; }
public Nullable<int> IngredientTypeID { get; set; }
}
And controllers:
public ActionResult AddIngridient(int id = 0)
{
IEnumerable<Ingredient> ListOfIngridient = FRE.Ingredient.Select(key => key).ToList();
ViewBag.IngridientsList = new SelectList(ListOfIngridient,"IngredientID", "IngredientName");
IEnumerable<Amount> ListOfAmounts = FRE.Amount.Select(key => key).ToList();
ViewBag.AmountsList = new SelectList(ListOfAmounts, "AmountID", "AmountName");
ViewBag.ID = id;
return View();
}
[HttpPost]
public ActionResult AddIngridient(Ingredients ingridients)
{
return View();
}
View looks like:
@model FoodRecipes.Models.Ingredients
@{
ViewBag.Title = "AddIngridient";
}
<h2>AddIngridient</h2>
@using(Html.BeginForm())
{
@Html.DropDownListFor(model => model.IngredientTypeID, (SelectList)ViewBag.IngridientsList)
<br />
@Html.DropDownListFor(model => model.AmountID, (SelectList)ViewBag.AmountsList)
<input type="submit" value="Create" />
}