Guest User

Untitled

a guest
Jan 13th, 2013
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. [HttpPost]
  2. public ActionResult Create(int recipeID, RecipeStep newRecipeStep)
  3. {
  4. try
  5. {
  6. var recipe = db.Recipes.Single(r => r.recipeID == recipeID);
  7. recipe.RecipieSteps.Add(newRecipeStep);
  8. db.SaveChanges();
  9. return RedirectToAction("Index", "Recipe");
  10. }
  11. catch
  12. {
  13. return View();
  14. }
  15. }
  16.  
  17. public class RecipeViewModel
  18. {
  19. public int RecipeId { get; set; }
  20. public RecipeStep RecipeStep { get; set; }
  21. }
  22.  
  23. public ActionResult Create()
  24. {
  25. var recipeId = 10 // however you want to select that Id
  26.  
  27. var recipeViewModel = new RecipeViewModel {RecipeId = 10}
  28.  
  29. return View(recipeViewModel);
  30. }
  31.  
  32. [HttpPost]
  33. public ActionResult Create(int recipeID, RecipeStep newRecipeStep)
  34. {
  35. //your code
  36. }
  37.  
  38. @model MvcApplication3.Models.RecipeViewModel
  39.  
  40. @using (Html.BeginForm(null,null,FormMethod.Post))
  41. {
  42.  
  43. <div>
  44. <p>@Html.HiddenFor(x=>x.RecipeId) </p>
  45. <p>@Html.TextBox("RecipeStepData1")</p>
  46. <p>@Html.TextBox("RecipeStepData2")</p>
  47. <p>@Html.TextBox("RecipeStepData3")</p>
  48. </div>
  49. <input type="submit" value="Submit" id="btn" />
  50. }
Add Comment
Please, Sign In to add comment