Difference between Master Page and MVC View Master page - asp.net-mvc

Please check below screen shot. What is main difference between Master Page and MVC View Master page.
When I should use Master page and when I should use MVC View Master page.
Thanks.
alt text http://mahingupta.com/mahingupta/public/img/MsaterPage.png

The difference is the base class. In an ASP.NET MVC application you should use MVC View Master Page which derives from ViewMasterPage and you have access to helpers and it can be strongly typed to a model.

Related

ASP.NET MVC: Load PartialView Only Once

We are using ASP.NET MVC 4 and KO (KnockOutJS) for frontend side.
For making components in KO, we are using ASP.NET MVC partial views (consist of script and template).
Some of our components depend on another component so we load some partials in another partial view to make sure dependent component exists in page.
The problem is that in such cases multiple instance of one partial load in page.
Is there any way to tell the view engine to load every partial only once in each page?
Any idea will appreciated ...
Thanks

How to pass data from MVC Controller to ASPX Page?

I have two projects (one ASP.NET MVC and one ASP.NET Webform). I am showing the aspx page of webform project in one panel of the cshtml page of MVC project.
I wanted to pass a value from the action method of controller to the aspx page and I need to use it in the webform project. Could some one help how to achieve this?
Thanks in advance!

Upgrading ASP.NET MVC2 project to MVC3 and using mixed View Engines

Can I upgrade my MVC2 project to MVC3 and continue to use my ASPX views, AND at the same time start writing some new views in Razor?
More specifically, Can I take an ASPX view page, and a Razor control in it? Would such a thing be possible?
Any other things one should look out for?
You can definitely mix view engines across totally separate views. As for putting Razor "controls" in an ASPX page, if you use RenderPartial, it should work.
One thing I would watch out for is that if you use Master Pages then you may end up duplicating them for both view engines. I had a good ol' WebForms Master Page, used by all my regular .aspx content files, but creating a new view using Razor means I have to use a duplicate Razor layout page alongside that old Master Page.
I haven't looked into it too much, but at first try I get 'The file "~/Views/Shared/Site.Master" could not be rendered, because it does not exist or is not a valid page.' and certainly there's nothing in Scott Gu's blog entry introducing Razor to suggest you can combine them, but I could be all wrong here.
http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
For how to mix view engine master pages...

Using asp.net site.master and spark views

Is it possible to use my site.master master page ? I want to start using Spark more, but this project I am working on is using asp.net view pages as well.
I could of course convert the master page to an application.spark page, but I was wondering if it is at all possible to use the Site.Master I already have.
As far as i remember, had no problems with this. There are questions in stack that says there are.
Scenario that will work for sure - double your site.master in spark (make 2 master pages).

Is it possible to share a masterpage between MVC and webforms?

I am adding MVC to a project that has MANY legacy webform pages. This works fine. However, I currently have a separate masterpage for MVC and for the webforms. The two master pages produce essentially identical output. I'd really like to kill the webforms one and just use the MVC master page with all my pages and stay DRY.
Not being DRY has already bitten me a couple times when I forgot to change both.
I tried doing the obvious way and just pointing the webform content page's MasterPage attribute at the MVC masterpage. This throws an error saying the MVC masters only work with MVC views.
This seems like it would be a pretty common problem with mixed MVC and webform projects. My MVC master isn't doing anything with ViewData, so I don't see any reason the webforms couldn't use them.
You can absolutely share the same master page. Your MVC master page must simply point to the WebForms masterpage via its MasterPageFile attribute. This applies your WebForms MasterPage styles to your MVC MasterPage.
I am using this setup in production.
The declaration on my MVC Master Page, pointing at the Web Forms Master Page:
<%# Master Language="C#" MasterPageFile="~/MasterPage/Site.Master"
AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage" %>
Works like a charm.
This blog post walks you through the necessary steps to share WebForm and MVC master pages with little or no duplication. It also includes a sample project you can download, and I found it quite helpful.
One hiccup I ran into was that I was using a LoginStatus control in my header. LoginStatus must be inside a form so I couldn't use it in my root master page (not wanting to end up with nested forms on all my MVC pages). But that was a pretty easy control to replace with a simple code block in my root master page.
In my webforms app, my master page inherits from "HLPUSD.SMART.SMARTMaster" which is just the namespace for our application and then the name of the webform class.
In my MVC project, the master page inherits from "System.Web.Mvc.ViewMasterPage"
Me thinks this has something to do with it?

Resources