asp.net-mvc-2

What are Best Practices for Property Declaration in a Custom ViewModel

In my new UserViewModel that I'm building for my application, I have two options for storing properties. The first option is to have Public Property user As User ''# Including the entire User object Public Property custString as String ''# Custom String for View The second option is to actually write out all the Use...

How do I get the value of an input of html.textbox in ASP.NET MVC 2

Hello all, I currently have a TextBox using: <%: Html.TextBox("TextBox1") %> How do I get the value of what is typed into the TextBox as a string so that I can use that string variable throughout my application? The view has he following with the inherits on top of page to model. This page is named "InputNumbersSection": <%: Html.Te...

Is there a HTML code beautifier?

I would like to beautify my HTML before it hits the user's browser. Is there any free or open source libraries that do this? ...

Dynamically set the view base type for a partial view?

Hi, Is it possible to dynamically set the view base type for a partial view? I'm doing a lot of dynamic page generation, using custom IViewFolder and IViewFile implementations, and need to set a specific base type for certain views...it's not a problem injecting the correct block, I just need to know what block to inject. I've ...

what are the changes, if any, to File Uploads with MVC version 2

There are numerous posts on doing File uploads with MVC, the most commmon link being to Scott Hanselman's blog which is certainly a good read. However in this article there is mention: This post is out of date. It talks about an earlier version of the MVC Framework. Please check the ASP.NET MVC documentation for how to do file uplo...

Using any type for MVC2 client side validation not just the Model

It seems that with MVC2 client side validation the type used to derive the validation rules from is fixed to the type of the Model of the View. I don't want to be bound to having the same ViewModel shape in and out. I want to take a message approach to action methods. With xVal you where give the option to specify the type used for c...

setting displayname data annotation dynamically in asp.net mvc

I have a database table with the following fields item_key, item_value, display_name, uihint I want to be able to specify in the database table which displaytemplate to use and also the displayname. <%= Html.EditorFor(p=>pageField.item_value, pageField.uihint) %> The UIHint is working, but I can't work out a way of setting the disp...

mvc 2.0 Jquery Validate decimals

Hi, I'm using Jquery validate with future mvc. I got one problem my application use globalization and each decimal is display according to globalization, and I need to get jquery validate to use different comma separators for decimal. Example: "100.00" ok "100,00" error Anyone have solution for it? ...

ASP.NET MVC 2 Multiple PartialView Forms fieldname conflict

I have a ASP.NET MVC 2 webpage in which I render multiple PartialViews of the same type. Each partial view contains a Ajax-form for posting smth. The form consists of: an input: EditorFor(m => m.content) the validation for the input: ValidationMessageFor(m => m.Content) The problem is that because there are more than 1 of these forms...

asp.net mvc 2.0 Model validate

Hi, I have model with 2 list of string example: [Required] public List<string> prop1 { get; set; } [Required] public List<string> prop12{ get; set; } I would like to see that my Model State is validate if each element of list isn't empty. I know that I can create class that will contain string as prop...

ASP.NET MVC how can I return an error from a file download action without leaving the current page?

I am calling a file download action from javascript: $elem.click(function() { window.location.href = 'MyController/MyFileDownloadAction'; }); The controller returns a file: [AcceptVerbs(HttpVerbs.Post)] public ActionResult MyFileDownloadAction() { /* do some processing, generate an in-memory file... */ return File(myFil...

ASP.NET MVC LINQ-2-SQL as model - how to update?

Is it possible to use LINQ2SQL as MVC model and bind? - Since L2S "attachement" problems are really showstopping. [HttpPost] public ActionResult Save(ItemCart edCart) { using (DataContext DB = new DataContext()) { DB.Carts.Attach(edCart); DB.Carts.Context.Refresh(RefreshMode.KeepChanges, edCart); DB.Carts.Context.S...

ASP.NET MVC 2, Validation, Localization, Argument List possible?

Hi there, I want to localize the error message for wrong user inputs. E.g. min. length of City name is 2 chars. [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Validation))] [StringLength(50, ErrorMessageResourceName = "Max", ErrorMessageResourceType = typeof(Validation))] [RegularExpression(".{2,}",...

Setup Multiple Project Areas with Visual Studio 2010, ASP.NET MVC 2.0

I am trying to go through the 'Multiple Project Areas' with MVC 2.0 in VS2010. I have looked at the 'Portable Areas' from MvcContrib and cannot get that to work right... the examples do not match the source code files... and furthermore the way it is done is just excessively difficult to use. I have been following this tutorial, for th...

.NET MVC : Pass back complex object or list array from view to controller

Hi, I want to pass a list array from the View to the controller on submission of the form. I can pass back simple values by using the Html.hidden() function. But how does one pass back a complex object or a List array ...

load different css for site localization

I need to load different css file depending on the language that the user selects. I need to do this only in my master page. ...

"Run Custom Tool" for resx files in MVC2 project (from an external application/script)

I am trying to get the localization for my MVC project working with our existing infrastructure for editing string resources. We store all our resource string in database tables and have a front end web UI to edit them with, and an export application which generated the .resx files. This all works great, but I am having a little difficul...

asp.net MVC 2.0 REST service with FormCollection

Hi there, Let's say the Action below is exposed via REST service and is called from a different appliation how would it handle the posted data/object? Should I use Create(FormCollection collection) here? [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Member member) { .... } ...

How to use TextBoxFor to update the many side of a relationship

Suppose I have passed in a viewmodel with a PERSON record with multiple addresses I'm looking to write a view something like this (simplified) <% foreach (var addr in Model.PERSON.ADDRESSES) { %> <li> <%: Html.TextBoxFor(m => addr.Add1)%> </li> <% } %> Which appears to display as expected, however, each generated Text...

GET and POST to same Controller Action in ASP.NET MVC

I'd like to have a single action respond to both Gets as well as Posts. I tried the following [HttpGet] [HttpPost] public ActionResult SignIn() That didn't seem to work. Any suggestions ? ...