Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult Create(int recipeID, RecipeStep newRecipeStep)
- {
- try
- {
- var recipe = db.Recipes.Single(r => r.recipeID == recipeID);
- recipe.RecipieSteps.Add(newRecipeStep);
- db.SaveChanges();
- return RedirectToAction("Index", "Recipe");
- }
- catch
- {
- return View();
- }
- }
- public class RecipeViewModel
- {
- public int RecipeId { get; set; }
- public RecipeStep RecipeStep { get; set; }
- }
- public ActionResult Create()
- {
- var recipeId = 10 // however you want to select that Id
- var recipeViewModel = new RecipeViewModel {RecipeId = 10}
- return View(recipeViewModel);
- }
- [HttpPost]
- public ActionResult Create(int recipeID, RecipeStep newRecipeStep)
- {
- //your code
- }
- @model MvcApplication3.Models.RecipeViewModel
- @using (Html.BeginForm(null,null,FormMethod.Post))
- {
- <div>
- <p>@Html.HiddenFor(x=>x.RecipeId) </p>
- <p>@Html.TextBox("RecipeStepData1")</p>
- <p>@Html.TextBox("RecipeStepData2")</p>
- <p>@Html.TextBox("RecipeStepData3")</p>
- </div>
- <input type="submit" value="Submit" id="btn" />
- }
Add Comment
Please, Sign In to add comment