This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 13th, 2013  |  syntax: None  |  size: 1.18 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data