asp.net-mvc-2

HttpModule with ASP.NET MVC not being called

流过昼夜 提交于 2019-12-01 03:27:14
I am trying to implement a session-per-request pattern in an ASP.NET MVC 2 Preview 1 application, and I've implemented an IHttpModule to help me do this: public class SessionModule : IHttpModule { public void Init(HttpApplication context) { context.Response.Write("Init!"); context.EndRequest += context_EndRequest; } // ... etc... } And I've put this into the web.config: <system.web> <httpModules> <add name="SessionModule" type="MyNamespace.SessionModule" /> </httpModules> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="SessionModule" /> <add name=

What is the default behaviour of a controller action not marked with AcceptVerbs, HttpGet or HttpPost?

◇◆丶佛笑我妖孽 提交于 2019-12-01 03:21:49
If I create a controller action and do not decorate it with AcceptVerbs , HttpPost or HttpGet . What is the default behaviour? Does the action allow any access method or does it default to GET ? It's accessible via any verb. In Web API 2.1: it depends on the name of the action. If the action starts with "Get*" then it will default to only accept GET requests. If it starts with "Put*" then it will default to only accept PUT requests. Same with POST. If it doesn't start with any known verb then it will default to only accept POST. Here are the results of my testing: public class BlahController :

Global action filter in ASP.NET MVC

跟風遠走 提交于 2019-12-01 03:10:26
问题 Is it possible to create a global action filter that will automatically apply to all actions in all controllers in ASP.NET MVC application? I want something like "before_filter" defined in ApplicationController in Ruby on Rails. Thank you for your help. 回答1: This really depends what you want to do with it. In many scenarios, the previous answers by vucetica and Adeel will be what you actually want to do. However, neither of them meet the criteria you listed: automatically apply to all actions

Edit and Continue does not Work in VS 2010 / ASP.Net MVC 2

本秂侑毒 提交于 2019-12-01 02:59:08
Although Enable Edit and Continue is checked on the Web tab of my ASP.Net MVC 2 project, I cannot in fact change the source code while running. For example, if I try to edit a controller while paused in the debugger, I cannot change the file (acts as if read only). I found a related post Edit and continue in ASP.NET web projects , however The answers seem to suggest I should be able to at least edit the code, then reload the page to see the result. I don't know what the distinction is between a Web Application and Web Site projects The distinction is that a Web Application needs to be compiled

What is the best way to upload files with ASP.NET MVC 2?

狂风中的少年 提交于 2019-12-01 02:19:43
问题 What is the best method for uploading files of variable size (either very large or very small to an ASP.NET MVC 2 application file system)? This is what I understand so far: It seems like there are two ways that people handle this. (Let's assume the files may be very large or very small) (1) Handle the upload in a controller action via Request.Files or HttpPostedFileBase , which seems to have a drawback of taking a long time because ASP.NET loads the files into active memory. or (2) intercept

MVC2: Impossible to change the name with TextBoxFor?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 02:18:12
问题 I want to manually define id and name for textbox like that: <%: Html.TextBoxFor(model => model.Name, new { @id = "txt1", @name = "txt1" })%> But only the id is changed, not the name attribute, why? <input id="txt1" name="Name" type="text" value=""> Thank you! 回答1: You can't use the strongly typed lambda version for this, you'd need to use the older version Html.TextBox("txt1",new {@id = "txt1"}) 回答2: This is ok: <%: Html.TextBoxFor(model => model.Name, new { Name = "txt1" })%> Do you write "

Wondering why DisplayName attribute is ignored in LabelFor on an overridden property

大兔子大兔子 提交于 2019-12-01 02:17:42
today I got confused when doing a couple of <%=Html.LabelFor(m=>m.MyProperty)%> in ASP.NET MVC 2 and using the [DisplayName("Show this instead of MyProperty")] attribute from System.ComponentModel . As it turned out, when I put the attribute on an overridden property, LabelFor didn't seem to notice it. However, the [Required] attribute works fine on the overridden property, and the generated errormessage actually uses the DisplayNameAttribute. This is some trivial examplecode, the more realistic scenario is that I have a databasemodel separate from the viewmodel, but for convenience, I'd like

IValueProvider in MVC 2 RC 2

泪湿孤枕 提交于 2019-12-01 02:16:24
问题 I have been working with MVC 2 and it seems that at some point of time the ModelBindingContext.ValueProvider class has been removed and replace with IValueProvider. Because of this im having trouble iterating through the ValueProvider.Keys. Here is an example and the message I receive from Code complete private void foo(ModelBindingContext myMBC) { var myImportantKeys = myMBC.ValueProvider.Keys.where(keyValue => keyValue.StartsWith("important", StringComparison.InvariantCulture); foreach(var

Create a Mvc2 Project with Razor View Engine

大兔子大兔子 提交于 2019-12-01 02:01:59
问题 I've read how to use Spark View Engine instead of Webform View Engine in a Mvc2 Project so I think we can do the same with Razor View Engine but when I search on GOOGLE, I cant find anything helpful. So, to you pros I post this question. Please help! Thanks so much! Attention: Razor in Mvc2 project, not in Mvc3. Thanks again! 回答1: While this is technically possible, you'll need to copy vast swaths of code from the MVC3 source. Razor will still need .Net 4.0, so this is really not worth it;

Hierarchical menu in view based on parent child class

六月ゝ 毕业季﹏ 提交于 2019-12-01 01:55:01
I have a ViewModel: public class Page { public int Id { get; set; } public Page Parent { get; set; } public string Name { get; set; } public string Title { get; set; } } I am passing that model to a view, and i need to create a hierarchical menu based on the model: <ul> <li>Page <ul> <li>Sub Page</li> </ul> </li> Through no lack of effort at all i am unable to figure out how i will be doing this recursive loop in the view. I can create the markup in my controller, but that's not test friendly. Any Ideas? there are many ways to display dynamicly generated menus and i will post my way of doing