Wednesday, July 31, 2013

Tuesday, July 30, 2013

Get IE to display JsonResult instead of prompt to download

return Json(bm, "text/html", JsonRequestBehavior.AllowGet);

Html.ValidationSummary always showing

added this to fix

   <style type ="text/css">
    .validation-summary-valid { display:none; }
    </style>

[ControllerAction] deprecated and illegal

use [NonAction] instead

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);
        }



Deploying MVC

you may need to use  Add Deployable Dependencies Dialog Box

Links to Other Views In MVC

<%= Html.ActionLink("herby", "ViewList", "View")%>


I am getting
The call is ambiguous between the following methods or properties:
'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, string)' and
'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, string)'
however - though it compiles

set as start page changes this


VS & sql server integration

Opening SP's and scripts would crash my VS

I needed to run the msi'd stored here:
en_visual_studio_2010_ultimate_x86_dvd_509116\WCU\DAC

Adding a code behind manually to MVC view

I have vs2010 ultimate and I needed to exclude from project and then add

also I had to convert to asp project - very bizzare

Thursday, July 25, 2013

mixed aspx/mvc sites

  public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

should be in the global asax


(i have found that it works without this - don't know why)

Wednesday, July 24, 2013

orchard mvc style addresses

adding a trailing "/" in orchard will produce a

Not found

The page you are looking for does not exist.

Friday, July 12, 2013

sql server question

select null as boris into xxxx

creates a int column


why?

Tuesday, July 2, 2013

isnullorempty for sql server

declare @s varchar(100)
set @s = null
select len(isnull(nullif(@s,''),''))