asp.net-mvc-2

passing action method parameter to ActionFilterAttribute in asp.net mvc

我只是一个虾纸丫 提交于 2019-11-30 01:58:12
I know that I can use the filterContext to get to it. However, this is not very flexible if the action method parameter is named differently. This should work: [HttpGet] [NewAuthoriseAttribute(SomeId = id)] public ActionResult Index(int id) { ... public class NewActionFilterAttribute : ActionFilterAttribute { public int SomeId { get; set; } ... but it does not (it does not even compile). Any ideas? Building on the answer from @Pankaj and comments from @csetzkorn: You pass the name of the parameter as a string then check the filterContext public class NewAuthoriseAttribute :

ASP.NET MVC and ViewState

帅比萌擦擦* 提交于 2019-11-30 01:55:06
Now I've seen some questions like this, but it's not exactly what I want to ask, so for all those screaming duplicate, I apologize :). I've barely touched ASP.NET MVC but from what I understand there is no ViewState/ControlState... fine. So my question is what is the alternative to retaining a control's state? Do we go back to old school ASP where we might simulate what ASP.NET ViewState/ControlState does by creating hidden form inputs with the control's state, or with MVC, do we just assume AJAX always and retain all state client-side and make AJAX calls to update? This question has some

CSS is not being applied after changes

大城市里の小女人 提交于 2019-11-30 01:41:21
I have problem where I can't apply the style in CSS in my ASP.NET MVC application. The behavior is it applies for the first time and then the subsequent changes to the CSS is not getting reflected in my _Layout.cshtml. I am not sure what I am missing here. CSS file body { font-size: .85em; font-family: "Trebuchet MS", Verdana, Helvetica, Sans-Serif; color: #232323; background-color: #fff; } header, footer, nav, section { display: block; } /* Styles for basic forms -----------------------------------------------------------*/ fieldset { border:1px solid #ddd; padding:0 1.4em 1.4em 1.4em; margin

ASP.NET MVC - What is UrlRoutingModule?

回眸只為那壹抹淺笑 提交于 2019-11-30 01:25:50
问题 I was reading about Request life cycle in MVC. I got stuck in understanding the below line. The UrlRoutingModule Intercepts the Request Query - What is UrlRoutingModule? I searched a lot on google but could not found any useful 回答1: Requests to an ASP.NET MVC-based Web application first pass through the UrlRoutingModule object, which is an HTTP module. This module parses the request and performs route selection. The UrlRoutingModule object selects the first route object that matches the

RadioButtonFor in ASP.NET MVC 2

拜拜、爱过 提交于 2019-11-30 01:12:08
问题 Can someone provide a simple example of how to properly use Html.RadioButtonFor? Let's say it's a simple scenario where my model has a string property named Gender. I want to display two radio buttons: "Male" and "Female". What is the most clean way to implement this while retaining the selected value in an Edit view? 回答1: This question on StackOverflow deals with RadioButtonListFor and the answer addresses your question too (@Larsenal it also includes labels with the "for" attribute) 回答2:

ASP.NET MVC on IIS falls through to the static file handler

余生长醉 提交于 2019-11-30 01:08:08
I have a problem with an ASP.NET MVC site. These are the details: ASP.NET MVC 2 ASP.NET 4 integrated pipeline IIS 7.5 on Windows Web Server 2008 R2 Whenever I make a request for the app I get the "HTTP Error 404.0 - Not Found"-error and the detailed error information shows it is the static file handler that reports the error: Module: IIS Web Core Notification: MapRequestHandler Handler: StaticFile Error Code: 0x80070002 meaning that the request never entered the MVC stack. I should note that the IIS already serves a ASP.NET MVC 3 on the same app pool and a MVC 2 on a ASP.ENT 2 app pool. So it

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

拟墨画扇 提交于 2019-11-30 01:06:03
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 ? This is possible using the AcceptVerbs attribute. Its a bit more verbose but more flexible. [AcceptVerbs(HttpVerbs.Get|HttpVerbs.Post)] public ActionResult SignIn() { } More on msdn . Actions respond to both GETs and POSTs by default, so you don't have to specify anything: public ActionResult SignIn() { //how'd we get here? string method = HttpContext.Request.HttpMethod; return View(); } Depending on your

Where does TempData get stored?

怎甘沉沦 提交于 2019-11-30 00:57:45
问题 Where does TempData get stored in the ASP.NET MVC Framework (more specifically, ASP.NET MVC 2)? Is it stored at server-side, or is sent to the client? 回答1: By default TempData uses the ASP.NET Session as storage. So it is stored on the server ( InProc is the default). But you could define other ASP.NET Session state modes: StateServer and SqlServer. You could also write a custom TempData provider and handle the storage yourself if you don't want to use the ASP.NET Session. 回答2: It is stored

How do I implement custom Principal and Identity in ASP.NET MVC?

喜夏-厌秋 提交于 2019-11-30 00:25:18
I want to store extra information in the authenticated user so that I can have it easily accessible (like User.Identity.Id, for example), instead of just the name, since I'm planning on having that non-unique. So far I've gathered that I should look to implement custom Principal and/or Identity, but I'm not sure how to go about it. I've been looking for documentation and tutorials on the matter, but I've found related stuff in different places and I've found it a bit confusing. I have seen how to add custom info to the authentication cookie in the user data property, but I'd like to have the

Default resource for data annotations in ASP.NET MVC

若如初见. 提交于 2019-11-30 00:18:08
There's a way to set the default resource to the data annotations validations? I don't wanna make something like this: [Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)] public string Name { get; set; } I would like something like this: Global.asax DataAnnotations.DefaultResources = typeof(CustomDataAnnotationsResources); then [Required] public string Name { get; set; } someone gimme a light! thanks in advance EDIT My real problem was with EF Code First CTP4. CTP5 fix it. Thanks for everyone. You could try doing this: Add this class