actionresult

Why does ContentResult controller in ASP.NET MVC return UTF-16 when UTF-8 specified?

I have an ActionResult that returns XML for an embedded device. The relevant code is: return Content(someString, "text/xml", Encoding.UTF8); Even though UTF-8 is specified, the resulting XML is: <?xml version="1.0" encoding="utf-16"?> The ASP.NET MVC is compiled as AnyCPU and runs on a Windows 2008 server. Why is it not returni...

How to get ContentType for file in ASP.NET MVC when using File Action Method

Hi there, Attempting to use asp.net mvc's Action Result of File. So it would seem that I have to specify a ContentType for the file to be sent to the browser. Currently there is no real limit to what types of files may be sent to the browser in my application, so I can't always assume it will be a "text/pdf", for example. What's the b...

How to use MVC Action Results from regular web forms (faking ControllerContext)?

We have a pluggable framework that returns ActionResult objects that render things to a browser. One late breaking requirement is that our plugins should be callable from a regular ASP.NET Web Forms application. So far I have come up with this, which works for very basic ActionResults: public class ActionResultTranslator { HttpCo...

WebResponse to HttpResponseBase. Is it possible?

Hi, In a controller action, I am manually sending a form to a remote URL using WebRequest. I successfully receive a WebResponse containing an html page to display. I would like to "paste" this response as the Response (of type HttpResponseBase) of the action. An action normally returns an ActionResult, so how do I conclude my controller...

ActionResult helper and different types resolver

Idea is to use same action methods for different types of results I.E. /category/details/?resultFormat=json /category/details/?resultFormat=xml So to have some kind of ActionResult helper that contains registered pairs of value resolvers "json", JsonValueResolver "xml", XmlResolver etc...is there already solution fo...

How to handle different ActionResults for an ASP.NET MVC Controller Action

I have a not-so-ideal situation where uploaded files are stored on an internal network share. So in the database I'm storing the path to where the file was saved, but it's quite possible for the file to get deleted out of sync of the database. So in a Controller action I lookup the upload information and perform checks that things are ...

ActionResult redirect renders using ToString()

Using the following sample: http://www.west-wind.com/Weblog/posts/899303.aspx The following line... return req.RedirectingResponse.AsActionResult(); renders the string "DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult". This is the class being returned as ActionResult in the line as posted. Does anyone know why I get the clas...

Asp.Net MVC post action result

How do you set the result of an action result to use Post and not Get. I need to redirect the result to an external site that requires the data to be sent using the post method. (Would like to know also how to redirect to another action with a httpverbs.post filter - but not as important for me at this point). ...

Asp.Net MVC How to unit test an ActionResult that returns Content?

For instance if I wanted to unit test the following controller what do I replace ???? with? using System.Web.Mvc; namespace MvcApplication1.Controllers { public class StatusController : Controller { public ActionResult Index() { return Content("Hello World!"); } } } [TestMethod] public v...

ASP.NET MVC: Can't figure out what VirtualPath is?

I have a View that displays a list of images and i am now trying to get it to display the images as thumbnails. Well, i'm pretty sure i got most of it right using VirtualPath's from a custom ActionResult although i can't seem to figure out what it is making the VirtualPath url?? BTW, i'm using XML to store the data from the images inst...

RedirectResult and cookies

I have a method that figures out what to do with a user after protected override ActionResult RedirectFromReg1(IPrincipal u) { if something.... { return RedirectToAction("LogIn", "Account"); } return null; } The calling code then ret...

Strang ASP.NET MVC behavior

i have a controlled called AppController. i have 2 actions: Details and Delete both pass in int id as the parameter to the action WHen i go to: mysite/App/Details/100 I can catch it in the controller details action but when i go to mysite/App/Delete/100 The breakpoint never hits and i get this in the browser: Server Error in '...

ASP.NET MVC Base Controller Function not firing when I need it to.

I'm noticing some behavior that I don't like, and I'm wondering if this is normal. I've got a BaseController that is Inheriting from Mvc.Controller, and I've got a View function inside that is to fire on every page load. Protected Overrides Function View(ByVal viewName As String, ByVal masterName As String, ByVal model As Object) As ...

Return int from MVC Action with Ajax.BeginForm

Whats the simplest way of just returning an int from an Ajax MVC Action call? I am currently trying: public ContentResult Create(MyModel model) { return Content("1"); } using (Ajax.BeginForm("Create", new AjaxOptions { OnComplete = "function(data) { alert(data); }" })) I get alert [object Object]. How...

After HttpPost, returning a View (ActionResult) when Model is not valid, the response has content type of application/json

I'm running into a strange issue in more than one page of my ASP.NET MVC site. When I POST a form and the Model is NOT valid, I try to return the same view so that I can see the errors - however, instead of the page getting reloaded, I get a pop-up download box that says that the file is in "application/json" format. As you can see fro...

Custom View Engine vs Custom Action Result

Hey! I have a scenario where the user have the option to click the button "download" and I should create a csv file, that contains history data, and then let the user save the file locally. As I haven't done this before, I started to look around for how to do this and basically came across both Custom View Engine, and Custom Action Resu...

MVC Handler for an unknown number of optional parameters.

I am workingon an MVC route that will take an unknown number of parameters on the end of the URL. Something like this: domain.com/category/keyword1/keyword2/.../keywordN Those keywords are values for filters we have to match. The only approach I can think of so far is UGLY... just make an ActionResult that has more parameters than I ...

How to unit test a custom actionresult

I'm trying to unit test a custom action result. I recently watched Jimmy Bogard's excellent MvcConf video ("put your controllers on a diet") http://www.viddler.com/explore/mvcconf/videos/1/ and have started to try and implement some custom action results. I've managed that without a problem, the ActionResult works fine at runtime but I'm...

onResult HTTPService

I have a HTTPService: <mx:HTTPService id="scoreService" url="http://" method="POST" result="onResult(event)"> <s:request xmlns=""> <name>{..}</name> <score>{...}</score> </s:request> </mx:HTTPService> And a script for (event): private function onResult(e:ResultEvent):void { ...

"Default decoder could not decode result"

Here are the files - MXML: <mx:HTTPService id="score" url="http://...score.php" fault="mx.controls.Alert.show(event.fault.faultString)" method="POST" result=""mx.controls.Alert.show(event.result.toString())"> <s:request xmlns=""> <name>{name}</name> <score>{score}</score> </s:requ...