asp.net-mvc-2

Can I get the controller from the HttpContext?

心已入冬 提交于 2019-11-30 04:12:24
Given an HttpContext (or HttpContextBase), is there a way to get an instance of the Controller? The HttpContext will hold a reference to the MvcHandler , which will hold a reference to the RouteData , which will hold a reference to what controller is being invoked by a particular route. NB: This doesn't give you the actual controller, only the controller that the specific route is going to catch. GetController(HttpContextBase httpContext) { var routeData = ((MvcHandler)httpContext.Handler).RequestContext.RouteData; var routeValues = routeData.Values; var matchedRouteBase = routeData.Route; var

What is the recommended approach to providing user notifications / confirmations in MVC?

こ雲淡風輕ζ 提交于 2019-11-30 04:07:52
A common scenario I encounter is providing notifications / confirmations to users after they have performed an action to inform them of success. For example, suppose a user provides feedback on a feedback form and then clicks Submit Feedback . You may want to display a 'Thanks for your Feedback' message after you have performed some validation e.g. they have a valid email in the database. Some pseudocode: public ActionResult SubmitFeedback(string Feedback, int UserID) { MyDataContext db = new DataContext() if(db.usp_HasValidEmail(UserID)) //Check user has provided a valid email return View(

Extract Display name and description Attribute from within a HTML helper

一世执手 提交于 2019-11-30 04:01:04
I am building a custom HTML.LabelFor helper that looks like this : public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> self, Expression<Func<TModel, TValue>> expression, Boolean showToolTip) { var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData); ... } To be able to get the proper name for the property I am using the following code : metadata.DisplayName And on the property of the ModelView class I got : [DisplayName("Titel")] The problem is that I also need a description. There is an Attribute called Display and that has Name and Description

How would you validate a checkbox in ASP.Net MVC 2?

风格不统一 提交于 2019-11-30 03:58:22
问题 Using MVC2, I have a simple ViewModel that contains a bool field that is rendered on the view as a checkbox. I would like to validate that the user checked the box. The [Required] attribute on my ViewModel doesn't seem to do the trick. I believe this is because the unchecked checkbox form field is not actually transmitted back during the POST, and therefore the validation doesn't run on it. Is there a standard way to handle checkbox "required" validation in MVC2? or do I have to write a

Deploying Asp.Net MVC 2 /C# 4.0 application on IIS 6

回眸只為那壹抹淺笑 提交于 2019-11-30 03:38:51
I got a problem migrating from VS.Net 2008 / MVC 1 to VS.NET 2010 (+C# 4.0) / MVC 2 The web.config has been updated , the site runs well in Cassini, but my problem now is deploying on IIS 6. I updated the web site to run using ASP.Net 4 , but whatever URL I try, I always have a 404 error. It's as if the routing was not taken into account (yes, the wildcard mapping has been done). I do not understand this mess and could not google anything interesting... Thanks for your suggestions ! Ok I got y answer (thanks to a colleague) When migrating from ASP.Net 2.0 to ASP.Net4.0, if you meet the same

How to overcome this security issue

淺唱寂寞╮ 提交于 2019-11-30 03:19:58
I have implemented an ajax-polling script that calls an action in the server Controller every 10 seconds. With the response, I replace the content of a div : function getFoo() { var link = '/Secure/GetFoo'; $.post(link, function (response) { $('#FooSection').replaceWith(response); }); setTimeout("getFoo();", 10000); } This is done through https . After some time of being "idle", IE displays the following message: This page is accessing information that is not under its control. This poses a security risk. Do you want to continue? If the user clicks Yes , the page is redirected to the div

How to deploy SQL CE 4 CTP to shared hosting?

半世苍凉 提交于 2019-11-30 03:18:35
问题 How do I deploy SQL CE 4.0 with EF4 to a shared hosting provider for ASP.NET MVC 2.0? I've included System.Data.SqlServerCe.dll, and the amd64 + x86 directories in my bin folder, but keep getting a ".net provider not found". I realize it's currently in CTP, but this is just for testing purposes. My project + host is configured for .net 4.0 回答1: With Visual Studio 2010 there is now an easy way to deploy SQL CE 4 to a shared hosting environment through the use of "Deployable Dependencies". You

How can I get all element values from Request.Form without specifying exactly which one with .GetValues(“ElementIdName”)

最后都变了- 提交于 2019-11-30 03:05:27
Currently using the below code to create a string array (elements) that contains all string values from Request.Form.GetValues("ElementIdName"), the problem is that in order for this to work all my dropdown lists in my View have to have the same element ID name which I don't want them to for obvious reasons. So I am wondering if there's any way for me to get all the string values from Request.Form without explicitly specifying the element name. Ideally I would want to get all dropdown list values only, I am not too hot in C# but isn't there some way to get all element ID's starting with say

TempData implementation changes - Reasons for the change

筅森魡賤 提交于 2019-11-30 02:56:45
问题 In ASP.NET MVC 2, the lifespan of an entry in the TempDataDictionary was just one HTTP Request. That translated to setting a value in one request, redirecting, and having access to the same item at the other end of the line. After this the entry would be no longer available, regardless of whether you read the value out of the dictionary at the latter end of the line or not. Since ASP.NET MVC 3 (I believe), this implementation detail has changed quite significantly. Entries in the

Cannot insert explicit value for identity column in table 'ClientDetails' when IDENTITY_INSERT is set to OFF

夙愿已清 提交于 2019-11-30 02:22:30
问题 I get this exception thrown whenever I try and submit data through a form to this database :- Exception Cannot insert explicit value for identity column in table 'ClientDetails' when IDENTITY_INSERT is set to OFF. However, the form doesn't have a field so data can enter the identity column (PK) so I'm at a loss as to why this is occuring. At the moment I'm using the standard asp.net mvc submit button but I will link it eventually to a jquery dialog button The ClientNo Column which is the said