Questions tagged [asp.net-mvc-2]

ASP.NET MVC 2 is the second major version of the ASP.NET MVC platform, it has since been outdated by ASP.NET MVC 3.

Filter by
Sorted by
Tagged with
256 votes
9 answers
533k views

Download file of any type in Asp.Net MVC using FileResult?

I've had it suggested to me that I should use FileResult to allow users to download files from my Asp.Net MVC application. But the only examples of this I can find always has to do with image files (...
Anders's user avatar
  • 12.7k
241 votes
8 answers
595k views

Showing Difference between two datetime values in hours

I am retrieving two date time values from the database. Once the value is retrieved, I need the difference between the two values. For that, I create a timespan variable to store the difference of the ...
reggie's user avatar
  • 13.6k
217 votes
4 answers
197k views

ModelState.AddModelError - How can I add an error that isn't for a property?

I am checking my database in Create(FooViewModel fvm){...} to see if the fvm.prop1 and fvm.prop2 already exist in that combination; if so, I want to add an error to the modelstate, then return the ...
Scott Baker's user avatar
  • 10.3k
216 votes
13 answers
324k views

How to set a default value with Html.TextBoxFor?

Simple question, if you use the Html Helper from ASP.NET MVC Framework 1 it is easy to set a default value on a textbox because there is an overload Html.TextBox(string name, object value). When I ...
dcompiled's user avatar
  • 4,772
216 votes
21 answers
174k views

jQuery Ajax calls and the Html.AntiForgeryToken()

I have implemented in my app the mitigation to CSRF attacks following the informations that I have read on some blog post around the internet. In particular these post have been the driver of my ...
Lorenzo's user avatar
  • 29.2k
158 votes
9 answers
90k views

How to specify an area name in an action link?

I have a shared master page which I am using from 2 different areas in my mvc 2 app. The master page has an action link which currently specifies the controller and action, but of course the link ...
Jeremy's user avatar
  • 45.6k
147 votes
7 answers
413k views

How to write a simple Html.DropDownListFor()?

In ASP.NET MVC 2, I'd like to write a very simple dropdown list which gives static options. For example I'd like to provide choices between "Red", "Blue", and "Green".
Rinesse's user avatar
  • 1,497
146 votes
3 answers
46k views

What is the difference (if any) between Html.Partial(view, model) and Html.RenderPartial(view,model) in MVC2?

Other than the type it returns and the fact that you call it differently of course <% Html.RenderPartial(...); %> <%= Html.Partial(...) %> If they are different, why would you call one ...
Stéphane's user avatar
  • 11.8k
144 votes
5 answers
481k views

Url.Action parameters?

In listing controller I have, public ActionResult GetByList(string name, string contact) { var NameCollection = Service.GetByName(name); var ContactCollection = Service....
user787788's user avatar
  • 1,575
122 votes
13 answers
112k views

How to set a Default Route (To an Area) in MVC

Ok this has been asked before but there is no solid solution out there. So for purpose of myself and others who may find this useful. In MVC2 (ASP.NET) I want it so when someone navigates to the ...
LiamB's user avatar
  • 18.4k
118 votes
4 answers
90k views

What are the Web.Debug.config and Web.Release.Config files for?

I just upgraded to Visual Studio 2010 and MVC 2.0 and I noticed the Web.config has two additional files attached to it? Are these files used to specify debug and release specific settings, so you don'...
chobo's user avatar
  • 31.9k
114 votes
20 answers
222k views

EditorFor() and html properties

Asp.Net MVC 2.0 preview builds provide helpers like Html.EditorFor(c => c.propertyname) If the property name is string, the above code renders a texbox. What if I want to pass in MaxLength and ...
chandmk's user avatar
  • 3,481
112 votes
2 answers
55k views

How do I use VaryByParam with multiple parameters?

In ASP.NET MVC2 I use OutputCache and the VaryByParam attribute. I got it working fine with a single parameter, but what is the correct syntax when I have several parameters on the method? [...
Frode Lillerud's user avatar
111 votes
4 answers
148k views

What does Html.HiddenFor do?

Although I have read the documentation on Html.HiddenFor, I've not grasped what is it used for... Could somebody explain its uses and give a short example? Where should those helpers go in the code?
JPCF's user avatar
  • 2,252
98 votes
3 answers
69k views

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 ?
Cranialsurge's user avatar
  • 6,144
96 votes
5 answers
88k views

ASP.NET MVC Model vs ViewModel

OK, I have been hearing discussion about "ViewModels" in regards to MS's ASP.NET MVC. Now, that is intended to be a specific kind of Model, correct? Not a specific kind of View. To my understanding,...
Qcom's user avatar
  • 18.7k
90 votes
12 answers
148k views

Getting index value on razor foreach

I'm iterating a List<T> in a razor foreach loop in my view which renders a partial. In the partial I'm rendering a single record for which I want to have 4 in a row in my view. I have a css ...
lloydphillips's user avatar
89 votes
8 answers
351k views

Percentage calculation

I am working in progress bar concept in ASP.NET MVC 2. Here i have a DropDownList which has 10 values. i want to calculate the percentage for progress bar, e.g. 10 values from DropDownList and i am ...
RobinHood's user avatar
  • 2,377
89 votes
3 answers
155k views

ActionLink htmlAttributes with hyphens

This works <a href="@Url.Action("edit", "markets", new { id = 1 })" data-rel="dialog" data-transition="pop" data-icon="gear" ...
Pavel Hlobil's user avatar
  • 1,782
86 votes
3 answers
50k views

What is the difference between [AcceptVerbs(HttpVerbs.Post)] and [HttpPost]?

I can decorate an action either with the [AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(string title) { // Do Something... } ...
Lorenzo's user avatar
  • 29.2k
84 votes
8 answers
124k views

How to implement reCaptcha for ASP.NET MVC? [closed]

How do I implement reCaptcha in ASP.NET MVC and C#?
Display Name's user avatar
  • 14.7k
82 votes
3 answers
119k views

Using Tempdata in ASP.NET MVC - Best practice

I am using ASP.NET MVC 3 to build a web application. What I am trying to do is pass values between two controllers, though there are many ways to do this I am particular interested in using TempData ...
Yasser Shaikh's user avatar
78 votes
12 answers
28k views

Unit tests on MVC validation

How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1? Some code to ...
Matthew Groves's user avatar
77 votes
7 answers
81k views

ASP.NET MVC - Catch All Route And Default Route

In trying to get my application to produce 404 errors correctly, I have implemented a catch all route at the end of my route table, as shown below: routes.MapRoute( "NotFound", _ ...
Sean Taylor's user avatar
  • 4,988
76 votes
7 answers
67k views

Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?

There was an Html.RadioButtonList extension method in ASP.NET MVC Futures. Has anyone found a code for a strongly typed version RadioButtonListFor<T>. It would look like this in a view: <%= ...
Keltex's user avatar
  • 26.4k
75 votes
2 answers
42k views

Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

A few days back I asked this question: Why does $.getJSON() block the browser? I fire six jQuery async ajax requests at the same controller action pretty much all at once. Each request takes 10 ...
Kev's user avatar
  • 119k
74 votes
3 answers
118k views

JSONResult to String

I have a JsonResult that is working fine, and returning JSON from some POCO's. I want to save the JSON as a string in a DB. public JsonResult GetJSON() { JsonResult json = new JsonResult ...
Dustin Laine's user avatar
  • 38.2k
73 votes
16 answers
63k views

"The Id field is required" validation message on Create; Id not set to [Required]

This is happening when I try to create the entity using a Create style action in Asp.Net MVC 2. The POCO has the following properties: public int Id {get;set;} [Required] public string Message {get;...
Dan's user avatar
  • 13.1k
69 votes
3 answers
156k views

When using .net MVC RadioButtonFor(), how do you group so only one selection can be made?

This one has me stumped, I have a strongly typed view that has this loop to generate radiobuttons: <% foreach (QuestionAnswer qa in Model.QuestionAnswers) { %> <%= Html.RadioButtonFor(...
Mark Kadlec's user avatar
  • 8,196
69 votes
4 answers
30k views

How to concatenate several MvcHtmlString instances

I have some doubts about how to concatenate MvcHtmlString instances because of this information found in MSDN : MvcHtmlString Class Represents an HTML-encoded string that should not be encoded ...
M4N's user avatar
  • 95.7k
68 votes
4 answers
130k views

ASP.Net MVC - Read File from HttpPostedFileBase without save

I am uploading the file by using file upload option. And i am directly send this file from View to Controller in POST method like, [HttpPost] public ActionResult Page2(FormCollection ...
Manikandan Sethuraju's user avatar
66 votes
3 answers
28k views

Get DisplayName Attribute without using LabelFor Helper in asp.net MVC

What is the best way to retrieve the display name attribute for an item in your model? I see a lot of people using the LabelFor helper for everything, but a label isn't appropriate if I just want to ...
Graham Conzett's user avatar
66 votes
5 answers
26k views

mvc: does the favicon.ico also look for a controller?

I get an error: "The controller for path '/favicon.ico' was not found or does not implement IController" Then I thought: how does the framework know for which files it has to instantiate a ...
Michel's user avatar
  • 23.3k
64 votes
4 answers
47k views

How to get the HTML id generated by asp.net MVC EditorFor

I use the HTML Helpers to render my fields: <%=Html.EditorFor(m => m.User.Surname)%> and the output would be something like this: <input class="text-box single-line" id="User_Surname" ...
LeftyX's user avatar
  • 35.5k
64 votes
8 answers
43k views

How can we set authorization for a whole area in ASP.NET MVC?

I've an Admin area and I want only Admins to enter the area. I considered adding the Authorized attribute to every controller in the Admin area. Isn't there an elegant solution or is this feature not ...
Abdulsattar Mohammed's user avatar
64 votes
3 answers
95k views

How to create Custom Data Annotation Validators

Wanting to create custom data annotation validation. Are there any useful guides / samples on how to create them? Firstly: StringLength with minimum and maximum length. I'm aware .NET 4 can do this, ...
SamWM's user avatar
  • 5,286
64 votes
9 answers
34k views

Service Layer vs Business Layer in architecting web applications?

I know this might sound silly but I am finding it hard to understand the need of a service layer and its differences with business layer. So, we are using asp.net mvc 2 and have Data Access layer ...
Vishal's user avatar
  • 12.3k
63 votes
8 answers
50k views

Can't run ASP.NET MVC 2 web app on IIS 7.5

I'm trying to run an ASP.NET MVC 2 web application under IIS on Windows 7, but I get a 403.14 error. Here are the steps to reproduce: Open Visual Studio 2010 Create a new ASP.NET MVC 2 project called ...
Portman's user avatar
  • 31.9k
62 votes
4 answers
116k views

Get a form action/url with jquery

How do I get the action url from a form with jquery?
Dejan.S's user avatar
  • 18.9k
61 votes
3 answers
35k views

How can I unit test my custom validation attribute

I have a custom asp.net mvc class validation attribute. My question is how can I unit test it? It would be one thing to test that the class has the attribute but this would not actually test that the ...
MightyAtom's user avatar
58 votes
12 answers
236k views

A default document is not configured for the requested URL, and directory browsing is not enabled on the server

I have just deployed my asp.net mvc-2 website to a server (using dotnetpanel). But getting this error A default document is not configured for the requested URL, and directory browsing is not enabled ...
coure2011's user avatar
  • 41.3k
58 votes
2 answers
97k views

How can I pass parameters to an Action using Html.Action() in ASP.NET MVC?

I've been using Html.Action("ActionName", "ControllerName") to invoke child actions across controllers without needing to have the view in Views\Shared. This has been working great for displaying ...
quakkels's user avatar
  • 11.7k
58 votes
4 answers
88k views

Python vs C#/.NET -- what are the key differences to consider for using one to develop a large web application?

My organization currently delivers a web application primarily based on a SQL Server 2005/2008 back end, a framework of Java models/controllers, and ColdFusion-based views. We have decided to ...
Aaron Silverman's user avatar
56 votes
7 answers
46k views

Adding sub-directory to "View/Shared" folder in ASP.Net MVC and calling the view

I'm currently developing a site using ASP.Net MVC3 with Razor. Inside the "View/Shared" folder, I want to add a subfolder called "Partials" where I can place all of my partial views (for the sake of ...
lamarant's user avatar
  • 3,311
55 votes
1 answer
63k views

Asp.net mvc override OnException in base controller keeps propagating to Application_Error

I am trying to return a view not issue a redirect to the user based on certain errors that could occur from my application, I want to handle the errors + log them inside my base controller, I do not ...
Haroon's user avatar
  • 3,452
53 votes
13 answers
17k views

Visual Studio 2010 Publish Web feature not including all DLLs

I have an ASP.NET MVC 2 application. Web project contains a reference to SomeProject SomeProject contains references to ExternalAssembly1 and ExternalAssembly2. SomeProject explicitly calls into ...
reustmd's user avatar
  • 3,553
51 votes
5 answers
35k views

Asp.Net MVC 2 - Bind a model's property to a different named value

Update (21st Sept 2016) - Thanks to Digbyswift for commenting that this solution still works in MVC5 also. Update (30th April 2012) - Note to people stumbling across this question from searches etc - ...
Andras Zoltan's user avatar
51 votes
3 answers
32k views

Need an ASP.NET MVC long running process with user feedback

I've been trying to create a controller in my project for delivering what could turn out to be quite complex reports. As a result they can take a relatively long time and a progress bar would ...
Jason's user avatar
  • 2,311
50 votes
4 answers
52k views

Can I get the controller from the HttpContext?

Given an HttpContext (or HttpContextBase), is there a way to get an instance of the Controller?
asbestossupply's user avatar
50 votes
5 answers
14k views

How many Include I can use on ObjectSet in EntityFramework to retain performance?

I am using the following LINQ query for my profile page: var userData = from u in db.Users .Include("UserSkills.Skill") .Include("UserIdeas.IdeaThings")...
teenup's user avatar
  • 7,549

1
2 3 4 5
169