asp.net-mvc-2

HttpModule with ASP.NET MVC not being called

痴心易碎 提交于 2019-12-30 08:07:11
问题 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>

How to specify date format for model binding?

与世无争的帅哥 提交于 2019-12-30 05:53:07
问题 I hope the question is easy, but I am searching around for more than an hour and I just do not find the answer. So I have a asp.net mvc 2 application and one of the forms contains a date textbox with a jquery datepicker. I have set in the datepicker the date format to be dd.mm.yyyy . My problem is that on the model binding this date is interpreted as mm.dd.yyyy , so by the time the model reaches my action method the DateTime attribute of the model is not correct (day and month is reversed, if

setInterval stops after Ajax request

落花浮王杯 提交于 2019-12-30 05:27:04
问题 I'm using Asp.net MVC and I want my partial view to refresh on an interval, which it does until I make an unrelated Ajax request, then it stops. Here are a few simplified snips to illustrate the problem. in AjaxRefresh.js: function ajaxRefresh() { var f = $("#AjaxForm"); $("#AjaxLoading").show(); $.post(f.attr("action"), f.serialize(), function (context) { $("#AjaxDiv").html(context); $("#AjaxLoading").hide(); }); } setInterval(ajaxRefresh, 1000); in Index.aspx: <script type="text/javascript"

Where to write Database and Business logic in MVC?

喜夏-厌秋 提交于 2019-12-30 03:58:19
问题 As I am learning and working on Asp.Net MVC application, I want to know that what is the better place to write Business Logic and Data Access logic in MVC . Where should I write DataAccess and Business Logic among three layers ( Model, View and Controller ) ?? Could anybody please tell me the correct way to write the code for this. Scenario: I want to retrieve all the employees where employee name like 'Mi%' ( I have SQL procedure to execute and retrieve the data. ) PS: Want to know that

C# UTC to Users Local Time

徘徊边缘 提交于 2019-12-30 02:33:04
问题 I have a site where users can make posts. The users can be from all over the globe so when they post, I am storing the posted date as DateTime.UtcNow. I am using the JQuery time ago plug in to show the posted dat similar to stack overflow (1 min ago etc...) But I am not sure how to convert to date I have stored in the system to the users local time? Here is what I am using: public static MvcHtmlString ConvertToLocalTime(this HtmlHelper htmlHelper, DateTime date) { DateTime convertedDate =

ASP.NET MVC - Uploading an image to Amazon S3

99封情书 提交于 2019-12-30 02:08:33
问题 I have my image from Request.Files[0]. Now, how do I upload this image to S3? I see that in the AWS .NET API you have to specify ContentBody when putting an object which is a string. How would I get the content body of my file? 回答1: var file = Request.Files[0]; PutObjectRequest request = new PutObjectRequest(); request.BucketName = "mybucket" request.ContentType = contentType; request.Key = key; request.InputStream = file.InputStream; s3Client.PutObject(request); 回答2: Slightly more detail

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

大憨熊 提交于 2019-12-30 00:41:18
问题 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

Pass object from JSON into MVC Controller - its always null?

荒凉一梦 提交于 2019-12-30 00:12:04
问题 I have seen a few questions on here related to the a similar issue, I have read them, followed them, but still i have the same problem. I am basically creating an object in javascript and trying to call a method on the controller that will return a string of html. Not JSON. I've been playing around with dataType and contentType but still no joy. So apologies if the code snippets are a bit messy. Build the object in JS. function GetCardModel() { var card = {}; card.CardTitle = $("#CardTitle")

Custom form authentication / Authorization scheme in ASP.net MVC

寵の児 提交于 2019-12-29 13:30:34
问题 I am trying to create a custom authentication scheme in ASP.NET MVC using form authentication. The idea that I might have different areas on the site that will be managed - approver are and general user area, and these will use different login pages, and so forth. So this is what I want to happen. User access restricted page (right now I have it protected with a customer AuthorizeAttribute) User is redirected to a specific login page (not the one from Web.config). User credentials are

ASP.NET MVC 2 Issue - Dot in Route

你离开我真会死。 提交于 2019-12-29 08:42:09
问题 I'm blanking and need a quick hand. Google has failed me. I'm working on replacing WCF/REST Starter Kit with ASP.NET MVC. I want to make the transition as painless as possible so I'm trying to create a route to match the following URL: http://localhost/services/MyService.svc/UserInfo I created the route in Global.asax.cs: routes.MapRoute( "MyServiceDefault", "services/MyService.svc/{action}/{id}", new { controller = "MyService", action = "UserInfo", id = UrlParameter.Optional } ); I soon