I want to have 2 models in one view. The page contains both LoginViewModel and RegisterViewModel.
e.g.
public class LoginViewModel
{
public string Email { get; set; }
public string Password { get; set; }
}
public class RegisterViewModel
{
…
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")
Custom Editor Template:
@Html.EditorFor(model =>…
I have a controller action that works fine on Firefox both locally and in production, and IE locally, but not IE in production. Here is my controller action:
public ActionResult MNPurchase()
{
CalculationViewModel calculationViewModel =…
public class EnumRouteConstraint : IRouteConstraint
where T : struct
{
private static readonly Lazy> _enumNames; // <--
static EnumRouteConstraint()
{
if (!typeof(T).IsEnum)
{
throw new…
I have a textarea control that accepts input. I am trying to later render that text to a view by simply using:
@Model.CommentText
This is properly encoding any values. However, I want to replace the line break characters with and I can't…
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 work properly. It will do an Ajax submit but…
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") })
As you see, the - is causing a problem here data-url.…
I've got a large site that runs in ASP.NET MVC using the Razor view engine.
I have a base stylesheet which contains all of the generic styling for the whole site. On occasion, however, I have page specific styles which in the of the page -…
I understand that in Razor, @Html does a bunch of neat things, like generate HTML for links, inputs, etc.
But I don't get the DisplayFor function...
Why would I write:
@Html.DisplayFor(model => model.Title)
when I could just write:
@Model.Title
I need to create a function that is only necessary inside one cshtml file. You can think of my situation as ASP.NET page methods, which are min web services implemented in a page, because they're scoped to one page. I know about HTML helpers…
I'm working on an MVC3 project and receive the following error:
Parser Error Message: Could not load type 'GodsCreationTaxidermy.MvcApplication'.
Source Error:
Line 1: <%@ Application Codebehind="Global.asax.cs"…
An expression tree may not contain a call or invocation that uses
optional arguments
return this.RedirectToAction(x => x.Edit(merchantId));
Where edit had a second, nullable argument.
Why is this?
I'm trying to figure out the proper Razor syntax to get a JavaScript file for a particular *.cshtml to be in the head tag along with all the other include files that are defined in _Layout.cshtml.
Buiding MVC3 solution went well but have got an error in browser:
Compiler Error Message: CS0234: The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)
Source Error:
Line 25: …