asp.net-mvc-3

Why do ASP.NET MVC3 Areas and Razor Views produce this error?

The view at '~/Areas/SomeArea/Views/List/Index.cshtml' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl. The project structure is pretty much default. There is one area called SomeArea. It has a single controller called List. It does nothing except: public ActionResult Index() { return View("~/Areas/SomeArea/...

How to specify default LayoutPage in Razor? [ASP.NET MVC 3]

Hi, I want to specify (in one place) a default layout page in Razor, so that I can delete this: @{ LayoutPage = "~/Views/Shared/_Layout.cshtml"; } from every .cshtml file I have. But I don't know how... Any ideas? I'm using Razor engine from ASP.NET MVC 3 Preview 1. ...

The new ViewModel doesn't obsolete the ViewModel pattern in ASP.NET MVC 3, right?

In my understanding, the ViewModel pattern was designed to pass all the relevant data to View because 1) the view shouldn't perform any data retrieval or application logic and 2) it enables type-safety, compile-time checking, and editor intellisense within view templates. Since dynamic expressions are defined at runtime, does this mean ...

What will be the designer surface for the razor view engine?

Razor looks like a winner for developers...close to the metal, yet quick and efficient. As a developer who is not good with a designer's stylus pen, at some point I want to pass my ham-handed design to a professional designer. What will be the design surface that such a designer will use? Will Expression Web be enabled with a knowled...

ASP.NET MVC 3 JSON ModelBinders not working

I'm trying to use the new JSON ModelBinders in MVC 3 which Scott Guthrie talks about in his blog. My example is very similar to the one he is using. I have a model with 3 values which I am trying to POST to the server. The model looks like this: public class CommentViewModel { public string Product { get; set; } public string...

'SampleApp.MvcApplication' is not allowed here because it does not extend class 'Microsoft.WebPages.WebPageHttpApplication'

I have created a sample project using ASP.NET MVC 3 Web Application (Razor) template. When I run my application I get this error 'SampleApp.MvcApplication' is not allowed here because it does not extend class 'Microsoft.WebPages.WebPageHttpApplication' Where should i look for the problem? ...

Escape @ character in razor view engine

A simple question though. I am creating a sample AP.NET MCV 3 site using Razor as view engine. The razor syntax starts with @ character e.g. @RenderBody(). If I write @test on my cshtml page it gives me parse error CS0103: The name 'test' does not exist in the current context. How do i escape '@' character? ...

IIS 7/ASP.NET 4/MVC 3 Preview 1: random "Could not load file or assembly" errors

I'm using the new Razor ViewEngine with ASP.NET 4/ASP.NET MVC 3. In both Cassini on my local machine (Win7 x64/VS 2010), as well as IIS7 (Windows Web Server 2008), I'm randomly getting "Could not load file or assembly" errors. With Cassini, rebuilding the solution generally fixes the problem. In IIS7, recycling the application pool ge...

Create User by profession - How to Populate/Submit/Validate form?

Hi geeks, I am trying to create user by registration form which contains dropdown for profession in ASP.NET MVC Eg. Individual, professional, manager etc. some fields are common like name & Last Name... some fields are unique by profession... how do i program it with ajax. Thanks ...

Decoding HTML in ASP.NET MVC 3

@ in asp.net mvc 3 preview 1 automaticly encodes html, is there an alternative way to let there be html? think of this scenario: @view.BestSitesEver.Replace("stackoverflow", "<h1>StackOverflow</h1>") That would just print out: <h1>stackoverflow</h1> ...

Possible to add shortcut names to razor namespace imports in MVC 3 web.config

Similar to using Shortcut = System.Whatever; in the cshtml I have so far been out of luck doing something similar in the webconfig <pages> <namespaces> <add namespace="System.Web.Routing" as="Routing" /> </namespaces> </pages> Something like that...Is it possible at all? ...

Return Razor partial view using JSON (ASP MVC 3)

In MVC 2 with the regular view engine i could return a ascx partial view as string through return Json() But with the new Razor .cshtml views I can not figure out how to do this. I keep getting Type 'ASP.CustomerForm_cshtml' does not inherit from 'System.Web.UI.UserControl'. The partial view inherits from System.Web.Mvc.WebViewPage<T> ...

Enable client validation in Razor views (ASP MVC 3)

I try to add client side validation using this line of code: @Html.EnableClientValidation() But I keep getting this error message: Compiler Error Message: CS1502: The best overloaded method match for 'Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)' has some invalid arguments Is this working for ...

Razor syntax inside attributes of html elements (ASP MVC 3)

I have a table with repeating customer rows, I would like to add the customer ID to the ID attribute of my table rows like this: <tr id="row<customer id>"></tr> I try adding this code: @foreach(var c in Model) { <tr id="[email protected]"></tr> } Which gives me the following output: <tr id="[email protected]"></tr> <tr id="[email protected]"></tr> etc....

ASP.NET MVC Razor Roadmap

I've been searching around on the Goog, but because technology moves so quickly, all my results are seemingly obsolete (brushing the dust off). I'm looking for the Razor Roadmap for MVC. I know it went preview, but I'm wondering about the full blown release. I really want to start using Razor, but I'm not sure what the implications wo...

Is there a better way to specify default section content in asp.net mvc razor layouts?

With the asp.net mvc web form engine, you could define a content placeholder and specify the default content. How is this done with Razor engine? This is the only way I found - but it seems like there would be a better way. _Layout.cshtml: @if (IsSectionDefined("Footer")) { @RenderSection("Footer") } else { <text>Default fo...

sending active href in view data asp.net MVC 3 @View. method

i am using asp.net MVC and have been using mvc for quite a while now but i have something along the lines of this: @View.greeting | <a href="/Login/Logout">LOGOUT</a> i have to but in the logout link as if i try to pass it over the @View will html encode and show the html of the link, i would prefer to deliver a result of login or log...

ModelState.IsValid vs IValidateableObject in MVC3

so according to Gu IValidatableObject.Validate() should get called when a controller validates it's model (i.e. before ModelState.IsValid) however simply making the model implement IValidatableObject doesn't seem to work, because Validate(..) doesn't get called. Anyone know if there is something else I have to wire up to get this to wor...

ASP.NET MVC save new record verse update existing record conventions

I'm working on my first ASP.NET MVC (beta for version 3) application (using EF4) and I'm struggling a bit with some of the conventions around saving a new record and updating an existing one. I am using the standard route mapping. When the user goes to the page /session/Evaluate they can enter a new record and save it. I have an action ...

Simplest Way To Do Dynamic View Models in ASP.NET MVC 3

Caveat: This might be an inappropriate use of C#'s dynamic keyword and I probably should be using a strongly-typed view model, but... I'm trying to avoid creating a strongly-typed view model by passing a C# 4 dynamic type to my view. I have this in my controller: public ActionResult Index() { var query = fro...