Monday, July 29, 2013

Linq Datatable subset as a datatable

blah.Rows.Cast<DataRow>().Where(row => row.Field<int>("ID").Equals(i)).CopyToDataTable();

will return onle where id = i

inserting partial views

<% Html.RenderPartial("heh"); %>

Parser Error Message: The type 'System.Web.Mvc.ViewPage' is ambiguous

fixed it thus:
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>

  </runtime>

also, look here.

New Razor @ Syntax

here

New Syntax for embedded html encoded text

<%:

Difference Between ViewBag & ViewData


Controller
[HttpGet]
        public ActionResult HerbyList()
        {
            HerbyModel hm = new HerbyModel();
            ViewData["HerbyList"] = hm.Herb;
            ViewBag.HerbyList = hm.Herb;
            return View();
        }

 View

//   this.GridView1.DataSource = (DataTable)ViewData["HerbyList"];
            this.GridView1.DataSource = ViewBag.HerbyList;

            this.GridView1.DataBind();  

Restricting MVC to Particular HTTP Verbs

[HttpGet]
        public ActionResult HerbyList()

        {

This is a perfect place to use Fiddler's composer - to change a regular page from a get to a post to test

also the older syntax:

[AcceptVerbs(HttpVerbs.Post)] 


an important use for this is one view for a get with default info and the same view for post to get the updated values  - example:

    [HttpGet]
        public ActionResult Update()
        {
            BookModel bm = new BookModel();
            bm.Author = "default";
            bm.Title = "default";

            return View(bm);
        }

        [HttpPost]
        public ActionResult Update(BookModel b)
        {
            return View(b);
        }