Posts

Showing posts with the label Action

Uploading files asynchronously in asp.net mvc site

Hi, I've been looking for quite some time for a complete solution to uploading files in ajax for my site. For those of you who don't know, browsers won't let you upload files without making a full page reload. I haven't been able to find a good, working and cross browser solution for this problem. So after much research and development I have finally managed to solve this problem. Lets take a look at the following controller. public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] public ActionResult UploadImage(HttpPostedFileBase image) { try { if (Request.ContentLength > 1024 * 1024 * 2) { return UploadCompanyLogoResult(new { success = false, error = "File size too big. Maximum file size is 2MB." }); } if (Request.Files.Count == 0) { return UploadCompanyLog...

Testing controller actions with ActionFilterAttribute in ASP .NET MVC

Hey, Have you ever wanted to test your controller actions with the logic you add with ActionFilterAttributes? Well, I did. So I wrote this helper class, which executes the ActionFilterAttribute methods. public class FilterAttributeTester { public ActionExecutingContext ExecuteOnActionExecuting<TAttribute>(Controller aController, Func<ActionResult> aAction) where TAttribute : ActionFilterAttribute { var actionExecutingContext = CreateActionExecutingContext(aController, aAction); var attribute = GetAttribute<TAttribute>(aAction); attribute.OnActionExecuting(actionExecutingContext); return actionExecutingContext; } public ActionExecutedContext ExecuteOnActionExecuted<TAttribute>(Controller aController, Func<ActionResult> aAction) where TAttribute : ActionFilterAttribute { var actionExecutedContext = CreateActionExecutedContext(aController, aAction); var attribute = GetAttri...