asp.net-mvc-2

Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items

When I create strongly typed View in Asp.net mvc 2, .net 4.0 with model type Tuple I get error when Tuple have more than 4 items example 1: type of view is Tuple<string, string, string, string> (4-tuple) and everything works fine view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web....

ASP.NET MVC Render Ajax / Standard View

I am a little confused and making it alot more complicated than this needs to be! Here is what I have... A view which displays a drop down of US States. When the user chooses a state it loads a list of data from a database and returns the results (populates the View Model) and the View renders the information. What I wanted to do was h...

ASP.NET MVC2 - Does Html.EnableClientValidation() work on the nested data model?

I have seen the client side validation examples and videos on internet by using Html.EnableClientValidation(). But all target on the simple data model. Does the Html.EnableClientValidation() work on the nested data model like below? public class Person { public Name Name { get; set; } public string Gender { get; set; } } ...

Render label for a field inside ASP.NET MVC 2 editor templates

I'm starting to use DataAnnotations in ASP.NET MVC and strongly typed template helpers. Now I have this in my views (Snippet is my custom type, Created is DateTime): <tr> <td><%= Html.LabelFor(f => Model.Snippet.Created) %>:</td> <td><%= Html.EditorFor(f => Model.Snippet.Created)%></td> </tr> The editor template for DateTime is...

Using xval to client side validate forms

Hello, I am using ASP.NET MVC2 and to validate the forms i use xVal. It seems like the server side validation works fine, but the client side validation doesnt work or atleast doesn't show up. The code i use looks like this: <% using (Html.BeginForm()) {%> div class="label"><label for="EmailAddress">Email Address</label></div> ...

How to retrieve value from DropDownListFor html helper in ASP.NET MVC2?

Hello I know there was few similar questions here about DropDownListFor, but neither helped me... I use Entity Framework as ORM in my project. There's EF model called "Stete". Stete has Foreign on EF model called "Drustva" Now I'm trying to make a form for editing the data, for Stete model. I managed to display everything, including S...

How to do role-based access control for a franchise business?

I'm building the 2nd iteration of a web-based CRM+CMS for a franchise service business in ASP.NET MVC 2. I need to control access to each franchise's services based on the roles a user is assigned for that franchise. 4 examples: Receptionist should be able to book service jobs in for her "Atlantic Seaboard" franchise, but not do any r...

MVC 2 AntiForgeryToken - Why symmetric encryption + IPrinciple?

We recently updated our solution to MVC 2, and this has updated the way that the AntiForgeryToken works. Unfortunately this does not fit with our AJAX framework any more. The problem is that MVC 2 now uses symmetric encryption to encode some properties about the user, including the user's Name property (from IPrincipal). We are able to...

Pass array of models from view to controller

Is it possible to pass array of models from view to controller? How? Suppose my model is public class Car { public string Name { get; set; } public int Price { get; set; } } And I have a <form> where user can dynamically add new cars. When he submits, I want to catch it in the a...

Why is always MasterName blank in OnActionExecuted?

I'm trying to get the master page changed for all my aspx pages. For some reason I'm unable to detect when this function is called for a ascx page instead. Any help in correting this would be appreciated. protected override void OnActionExecuted(ActionExecutedContext filterContext) { var action = filterContext.Result as ViewResult;...

Is there a good way of displaying required field indicators when using DataAnnotations in MVC 2?

I've got validation working with DataAnnotations on all my models, but I'd like to display an indicator for required fields on page load. Since I've got all my validation centralized, I'd rather not hard-code indicators in the View. Calling validation on load would show the validation summary. Has anyone found a good way of letting th...

ASP.NET MCV 2, re-use of SQL-Connection string

Hi, so I'm very very far from an expert on MVC or ASP.NET. I just want to make a few simple Controllers in C# at the moment, so I have the following question; Right now I have the connection string used by the controller, -inside- the controller itself. Which is kind of silly when there are multiple controllers using the same string. I...

Display a value in a disabled textbox using TextBoxFor

I'm trying to display a disabled textbox with the value 'FL' in it. Somehow the textbox does not have any value when it is displayed, but it is disabled. How do you display a value in a disabled textbox? <%= Html.TextBoxFor(model => model.State, new { value="FL", disabled="disabled" }) %> ...

Using LINQ to SQL in ASP.NET MVC2 project

Well I am new to this ORM stuff. We have to create a large project. I read about LINQ to SQL. will it be appropriate to use it in the project of high risk. i found no problem with it personally but the thing is that there will be no going back once started.So i need some feedback from the ORM gurus here at the MSDN. Will entity framewor...

Display empty textbox using Html.TextBoxFor on a not-null property in an EF entity.

I am using Entity Framework (v4) entities. I have an entity called Car with a Year property of type integer. The Year property does not allow NULL. I have the following in my Create view: <%= Html.TextBoxFor(model => model.Year) %> I am required to return a new Car object (due to other requirements) in my HttpGet Create action in the ...

Ajax comments form in ASP.NET MVC2, howto?

I've been playing around with different aspects of MVC for some time now, and I've reached a situation where I'm not sure what would be the best way to solve a problem. I'm hoping that the SO community will help me out here :P I've seen a number of examples of Ajax.BeginForm on the internet, and it seems like a very nifty idea. E.g. you...

ASP.NET MVC2 : How to use radiobuttons in a grid ?

Again a question about RadioButtons/ RadioButtonList I've the following Model: public class SkillLevelModel { public long? Id { get; set; } public int? SelectedLevel { get; set;} } I've the following Controller: public class SkillController : BaseController { public ActionResult Index() { ...

ASP.NET MVC 2 Areas, Strange routing behavior

I've created an Area named "Admin". I've created also a controller(Pages) and a view(List) in this areas. When I run my app and enter the url "/Admin/Pages/List" I'm getting an The resource cannot be found error. When I enter /Pages/List, the Action method is hit but the view is not found,because the app is searching in wrong directori...

asp.net mvc outputting json with backslashes ( escape) despite many attemps to filter

i have an asp.net controller that output Json as the results a section of it is here returnString += string.Format(@"{{""filename"":""{0}"",""line"":[", file.Filename); what i get returned is this: "{\"DPI\":\"66.8213457076566\",\"width\":\"563.341067\",\"editable\":\"True\",\"pricecat\":\"6\",\"numpages\":\"2\",\"height\":\"400\",...

How to reference using Entity Framework and Asp.Net Mvc 2

Tables CREATE TABLE [dbo].[Users]( [UserId] [int] IDENTITY(1,1) NOT NULL, [UserName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Email] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [BirthDate] [smalldatetime] NULL, [CountryId] [int] NULL, CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ([UserId] ASC )WITH (PAD_IN...