title: Create single View for all CRUD operations in MVC
body: <p>I am new in MVC.Want to apply simple CRUD operation using single View.I don't want separate views such as Create,Edit,Delete,Read.I am using Entity framework by code first approach.</p>
  
  <ol>
  <li>I want Text boxes to input data.</li>
  <li>Grid View which shows all information about particular master.</li>
  <li>buttons to perform operations(Add,Update,Delete).</li>
  </ol>
  
  <p>I have tried for following code.please help me to work this out....</p>
  
  <pre><code>    @model IEnumerable&lt;WareHouse.WareHouseType&gt;
      @{
          ViewBag.Title = "Index";
          Layout = "~/Views/Shared/_Layout.cshtml";
          WebGrid grid = new WebGrid(Model);
      }
      @using(Html.BeginForm) {
      &lt;div class="tdhdr1" &gt;Warehouse Type Details
              &lt;/div&gt;
  
  
      @grid.GetHtml( fillEmptyRows: true,
          alternatingRowStyle: "alternative-row",
          headerStyle: "tdhdr2",
  
          mode: WebGridPagerModes.All,
          firstText: "&lt;&lt; First",
          previousText: "&lt; Previous", nextText: "Next &gt;",
          lastText: "Last &gt;&gt;",columns: new [] {
          grid.Column("WareHouseTypeID",header: "ID", canSort: false),
          grid.Column("WareHouseTypeName",header:"Name ")
      })
      }
  </code></pre>
  
  <p>above code only for gridview.
  I want other controls also on same View.Is it possible by using Partial View?
  I cant add <strong>Editorfor().</strong> on same view.</p>
  
  <p>But it throws error  ** The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[WareHouse.WareHouseType]', but this dictionary requires a model item of type 'WareHouse.WareHouseType'. **</p>
  
  <p>Partial View Code     </p>
  
  <pre><code>@model WareHouse.WareHouseType
  
  @{
      Layout = null;
  }
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;title&gt;AddProduct&lt;/title&gt;    
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;      
             &lt;label&gt;Id:&lt;/label&gt;
              @Html.TextBox("Id", Model.WareHouseTypeID)
               &lt;label&gt;Name:&lt;/label&gt;
              @Html.TextBox("Name", Model.WareHouseTypeName)
  
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;                                                                                    
  </code></pre>
  
  <p>General View Code  :                                                                                     </p>
  
  <pre><code>    @model IEnumerable&lt;WareHouse.WareHouseType&gt;
      @{
          ViewBag.Title = "Index";
          Layout = "~/Views/Shared/_Layout.cshtml";
          WebGrid grid = new WebGrid(Model);
      }
  
      @using(Html.BeginForm()) {
      &lt;div class="tdhdr1" &gt;Warehouse Type Detailsdfgdgfdgdfg
              &lt;/div&gt;
  
          @Html.Partial("_WHT")
          @grid.GetHtml( fillEmptyRows: true,
          alternatingRowStyle: "alternative-row",
          headerStyle: "tdhdr2",
  
          mode: WebGridPagerModes.All,
          firstText: "&lt;&lt; First",
          previousText: "&lt; Previous", nextText: "Next &gt;",
          lastText: "Last &gt;&gt;",columns: new [] {
          grid.Column("WareHouseTypeID",header: "ID", canSort: false),
          grid.Column("WareHouseTypeName",header:"Name dfgsdfsdf")
      })
      } 
  </code></pre>
  
  <p>controller code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using WareHouse;
  
  namespace CommonMasterUI.Controllers
  {
      public class WHTypeController : Controller
      {
  
  
                WareHouse.Context ctx = new WareHouse.Context();
          IList&lt;WareHouseType&gt; list2 = new List&lt;WareHouseType&gt;();
          [HttpGet]
          public ActionResult Index()
          {
              IList&lt;WareHouseType&gt; wht = new List&lt;WareHouseType&gt;();  
              WareHouseRepository wr = new WareHouseRepository(ctx);
              wht = wr.GetWareHouseTP().ToList();
  
  
              for (int i = 0; i &lt; wht.Count; i++)
              {
                  WareHouseType wt = new WareHouseType();
  
                  wt.WareHouseTypeID = wht.ElementAt(i).WareHouseTypeID;
                  wt.WareHouseTypeName = wht.ElementAt(0).WareHouseTypeName.ToString();
                  list2.Add(wt);
  
              }
  
  
              return View(list2.ToList());
          }
      }
  }
  </code></pre>