142
votes
3answers
30k views
ASP.NET MVC 3 - Partial vs Display Template vs Editor Template
So, the title should speak for itself.
To create re-usable components in ASP.NET MVC, we have 3 options (could be others i haven't mentioned):
Partial View:
@Html.Partial(Model.Foo, "SomePartial")
...
135
votes
3answers
53k views
Writing/outputting HTML strings unescaped
I've got safe/sanitized HTML saved in a DB table.
How can I have this HTML content written out in a Razor view?
It always escapes characters like < and ampersands to &.
109
votes
1answer
35k views
ASP.Net MVC 3 Razor: Include js file in Head tag
I'm trying to figure out the proper razor syntax to get a js file for a particular *.cshtml to be in the head tag along with all the other include files that are defined in _Layout.cshtml
Thank you,
...
108
votes
5answers
89k views
Using Ajax.BeginForm with ASP.NET MVC 3 Razor
Is there a tutorial or code example of using Ajax.BeginForm within Asp.net MVC 3 where unobtrusive validation and Ajax exist?
This is an elusive topic for MVC 3, and I cannot seem to get my form to ...
82
votes
2answers
69k views
How to get current page URL in MVC 3
I am using the Facebook comments plugin on a blog I am building. It has some FBXML tags that are interpreted by the facebook javascript that is referenced on the page.
This all works fine, but I have ...
82
votes
5answers
32k views
Using MVC HtmlHelper extensions from Razor declarative views
I was trying to create a Razor declarative helper in my App_Code folder for an MVC 3 RTM project.
The problem I ran into was that the MVC HtmlHelper extensions, like ActionLink, aren't available. ...
78
votes
1answer
24k views
How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?
I would like to have 2 separate Layouts in my application. Let say one is for the Public section of the website and the other is for the Member side.
For simplicity lets say all the logic for each ...
76
votes
4answers
56k views
Multiple models in a view
I have want to have 2 models in a view. The page contains both LoginViewModel and RegisterViewModel.
For eg.
public class LoginViewModel
{
public string Email { get; set; }
public string ...
74
votes
1answer
10k views
Html5 data-* with asp.net mvc TextboxFor html attributes
How do I add data-* html attributes using TextboxFor?
This is what I currently have:
@Html.TextBoxFor(model => model.Country.CountryName, new { data-url= Url.Action("CountryContains", "Geo") })
...
72
votes
3answers
15k views
Does Razor syntax provide a compelling advantage in UI markup?
I notice Scott Guthrie is starting to mention Razor a fair bit on his blog but I'm just not that sure that it's a good fit for my style.
Granted it's a fairly unfamiliar style for someone who's ...
71
votes
3answers
15k views
ASP.NET: This method cannot be called during the application's pre-start initialization stage
I'm trying to get an ASP.NET MVC 3 site running on IIS 6.0.
Currently when I request a page from the server it gives the following error:
Parser Error Message: This method cannot be called during ...
66
votes
4answers
26k views
DisplayName attribute from Resources?
I have a localized application, and I am wondering if it is possible to have the DisplayName for a certain model property set from a Resource.
I'd like to do something like this:
public class ...
62
votes
2answers
47k views
MVC 3 file upload and model binding
I have a form upload that works but I would like to pass model information for my database to save the file with a different name of course.
Here is my Razor view:
@model ...
61
votes
9answers
33k views
Add css or js files to Layout Head from views or partial views
Layout pages head
<head>
<link href="@Url.Content("~/Content/themes/base/Site.css")"
rel="stylesheet" type="text/css" />
</head>
A View (AnotherView) from ...
60
votes
3answers
22k views
How to use knockout.js with ASP.NET MVC ViewModels?
Bounty
It's been awhile and I still have a couple outstanding questions. I hope by adding a bounty maybe these questions will get answered.
How do you use html helpers with knockout.js
Why was ...