asp.net-mvc-2

Get the selected drop down list value from a FormCollection in MVC

I have a form posting to an action with MVC. I want to pull the selected drop down list item from the FormCollection in the action. How do I do it? My Html form: <% using (Html.BeginForm()) {%> <select name="Content List"> <% foreach (String name in (ViewData["names"] as IQueryable<String>)) { %> <option value="...

ASP.NET MVC 2 - How do I use DropDownListFor ?

I have a simple model / view with things like Username, Password etc. and use helpers fine to hook it up. I now have a field called "NumberOfChildren". I want to store a number in it (int) and I want it render a dropdown box containing "None", "1", "2" etc. My thoughts would be that the model would have a list or a method that returns ...

Support for nested model and class validation with ASP.NET MVC 2.0

I'm trying to validate a model containing other objects with validation rules using the System.ComponentModel.DataAnnotations attributes was hoping the default MVC implementation would suffice: var obj = js.Deserialize(json, objectInfo.ObjectType); if(!TryValidateModel(obj)) { // Handle failed model validation. } The object is com...

Asp.Net MVC 2: How exactly does a view model bind back to the model upon post back?

Sorry for the length, but a picture is worth 1000 words: In ASP.NET MVC 2, the input form field "name" attribute must contain exactly the syntax below that you would use to reference the object in C# in order to bind it back to the object upon post back. That said, if you have an object like the following where it contains multiple Ord...

Asp.Net MVC 2: Any way to share data contracts with client side javascript?

If you have the following: Asp.Net MVC 2 project having object classes that define view models. Serialize these models to the web browser client using JSON. Client adds information to the objects, like an Order Line on an Invoice. Client sends back the object to the server for processing. Is there any way to share with the client a d...

Simple ASP.NET MVC views without writing a controller

We're building a site that will have very minimal code, it's mostly just going to be a bunch of static pages served up. I know over time that will change and we'll want to swap in more dynamic information, so I've decided to go ahead and build a web application using ASP.NET MVC2 and the Spark view engine. There will be a couple of cont...

ASP.NET MVC2 TeplatedHelper doesn't render an ID of the HTML's markup

Hi, I have the code (snippet): The Model is the IEnumerable object of the Person's class: <% foreach (var item in Model) { %> <tr> <td><%= Html.DisplayFor(x=>item.Name) %></td> </tr> <% } %> it renders only labels like that: <td>Tommy</td> According to the link it should be rendering a HTML markup somethi...

"potentially dangerous Request.Form value ..." -- mvc 2, .net 4.0

Hi -- I am trying to set up input validation using regular expressions, but I keep getting this error when I enter "<test>" in a textbox: A potentially dangerous Request.Form value was detected from the client I have this in the web.config: <system.web> <httpRuntime requestValidationMode="2.0" /> I also have this in the web.con...

ASP.NET MVC 2 A question about an Asynchronous Controller

Hi, I'm wondering about one thing - let's assume that the user clicks a button, and the asynch controller's action is invoked. What happens, when the asynchronous action takes e.g. 10 seconds? The user has to wait 10 seconds to view the result of the action? If so, are the asynch controllers really helpful ? ...

MVC2 client/server validation of DateTime/Date using DataAnnotations

The following are true: One of my columns (BirthDate) is of type Date in SQL Server. This very same column (BirthDate) is of type DateTime when EF generates the model. I am using JQuery UI Datepicker on the client side to be able to select the BirthDate. I have the following validation logic in my buddy class: [Required(ErrorMessage...

ASP.NET MVC 2 Areas 404

Hey, Has anyone been able to get the Areas in ASP.NET MVC 2 to work? I created a new Area called "Secure" and placed a new controller in it named HomeController. I then Created a new Home/Index.aspx view. However, when I browse to http://localhost/myapp/Secure/ it gives a 404 resource cannot be found. http://localhost/myapp/Secure/Hom...

Html.EditorFor Global Template?

Is there any way to define a global template for the Html.EditorFor helper? I would like to alter the markup that is output so that for example instead of rendering <div class="editor-label"> <label .../> </div> <div class="editor-field"> <input .../> </div> It would render: <div> <div class="label"><label..../></div> <d...

ASP.NET MVC: Why can't I set ShowForEdit model metadata with an attribute?

Why can't I set ShowForEdit model metadata with an attribute? It seems that the only attribute provided to alter this is [ScaffoldColumn], which sets both ShowForEdit and ShowForDisplay, which is not what I want to do. I want to be able to annotate the two separately from on my model. ...

Using ModelMetadata how do you call DisplayFor and have the metadata used

This question is based on using the Asp.Net MVC tabular layout display template from Phil Haack http://haacked.com/archive/2010/05/05/asp-net-mvc-tabular-display-template.aspx The problem is in the Html.DisplayFor(m => propertyMetadata.Model). This displays the data from the property just fine, however it doesn't use any of the data ann...

Change values in a ASP.MVC View between the controller parameter object and the object that will be post.

Hi, I have the next controller: public ViewResult AddPresentation(string categoryKey) { Category category = new Category(); category = repository.GetCategoryByKey(categoryKey); return View(category); } In the "AddPresentationView" I have to fill some object properties with values from the "AddPresentat...

date picker in two different browsers

Hello, i am workin on asp.net mvc in that i using partial views. i got one proble ie date picker is working properly on IE but it is not working on Mozilla Firefox. the i have used is: <link href="<%=ResolveClientUrl("~/Scripts/Themes/ui-lightness/jquery-ui-1.7.2.custom.css")%>" rel="stylesheet" type="text/css" /> <script src="../...

asp.net mvc 2 web application inside a Web site?

I have a Asp.Net Web Site deployed as a WebSite inside IIS 7.5. http://localhost/WebSite Then I have a second Asp.Net MVC 2 web application which is deployed as Sub Application inside the above WebSite. So the mvc aplication should work on the following Url. http://localhost/WebSite/MvcApp/ The web site works fine but when ...

Html.RenderAction - the controller for path '/' was not found

Using ASP.NET MVC 2 and and Html.RenderAction in my masterpage implemented as below throws an error with "the controller for path '/' was not found": I'm a bit of a newbie, do i have to do something in RegisterRoutes to make this work? <% Html.RenderAction("TeaserList", "SportEventController"); %> public class SportEventController : C...

How create and use two or more ViewData.Model 's

Hi guys. Can you help me how to create my own ViewData.Model from mesto? public ActionResult Index() { ViewData["Message"] = "Moji Priatelia"; var friends = from friend in friendsDb.FriendsTables orderby friend.Priezvisko select friend; var mesto =...

How to limit select items with L2E/S?

This code is a no-go var errors = (from error in db.ELMAH_Error select new { error.Application, error.Host, error.Type, error.Source, error.Message, error.User, error.StatusCode, error.TimeUtc }).ToList(); ...