actionresult

Must ASP.NET MVC Controller Methods Return ActionResult?

丶灬走出姿态 提交于 2019-11-27 11:32:22
Being new to ASP.NET MVC, I've been wondering about the signature of Controller methods. In all the examples I've seen, they always seem to return ActionResult, even if they actually return a ViewResult instance or similar. Here's a commonly seen example: public ActionResult Index() { return this.View(); } In such a case, wouldn't it make more sense to declare the method as public ViewResult Index() , and get stronger type support? Experimentation indicates that this works, so it seems possible. I do realize that there may be situations where the polymorphism is desired (e.g. if you want to

How do I pass a Dictionary as a parameter to an ActionResult method from jQuery/Ajax?

半城伤御伤魂 提交于 2019-11-27 04:07:30
I'm using jQuery to make an Ajax call using an Http Post in ASP.NET MVC. I would like to be able to pass a Dictionary of values. The closest thing I could think of was to pass in a multi-dimensional array of strings, but the result that actually gets passed to the ActionResult method is a single dimensional string array containing a string concatenation of the "key/value" pair. For instance the first item in the below "values" array contains the below value: "id,200" Here's an example of my ActionResult method: public ActionResult AddItems(string[] values) { // do something } Here's an example

MVC Controller Using Response Stream

一笑奈何 提交于 2019-11-27 02:21:26
问题 I'm using MVC 3 I would like to dynamically create a CSV file for download, but I am unsure as to the correct MVC orientated approach. In conventional ASP.net, I would have written something like: Response.ClearHeaders(); Response.ContentType = "text/csv"; Response.AddHeader("content-disposition", attachment;filename='Test.csv'"); Response.Write("1,2,3"); Response.End(); I have looked at the ContentResult action but it appears that I would need to create the result as a string, i.e. return

How to serve html file from another directory as ActionResult

笑着哭i 提交于 2019-11-27 01:45:53
问题 I have a specialised case where I wish to serve a straight html file from a Controller Action. I want to serve it from a different folder other than the Views folder. The file is located in Solution\Html\index.htm And I want to serve it from a standard controller action. Could i use return File? And how do I do this? 回答1: If you want to render this index.htm file in the browser then you could create controller action like this: public void GetHtml() { var encoding = new System.Text

How to pass List in Redirecttoaction

本小妞迷上赌 提交于 2019-11-26 22:18:27
问题 I want to pass more then one parameter from RedirectToAction method how can I pass? My One Action Method [HttpPost, ActionName("SelectQuestion")] public ActionResult SelectQuestion(string email,List<QuestionClass.Tabelfields> model) { List<QuestionClass.Tabelfields> fadd = new List<QuestionClass.Tabelfields>(); for (int i = 0; i < model.Count; i++) { if (model[i].SelectedCheckbox == true) { List<QuestionClass.Tabelfields> f = new List<QuestionClass.Tabelfields>(); fadd.Add(model[i]); } }

Struts 2 - Redirecting to a correct action after authentication interceptor

拜拜、爱过 提交于 2019-11-26 21:44:29
问题 I couldn't find anything online so I'll ask here. I'm using strut2 and I have a private package of actions, cause certain actions require login to be access. So I have this in my secure package: <interceptors> <interceptor name="authenticationInterceptor" class="com.koorde.interceptor.AuthenticationInterceptor"/> <interceptor-stack name="secureStack"> <interceptor-ref name="authenticationInterceptor"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> <default

How to return an XML string as an action result in MVC [duplicate]

旧巷老猫 提交于 2019-11-26 19:17:05
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What is the best way to return XML from a controller's action in ASP.NET MVC? I'm able to return JSON and partial views (html) as a valid ActionResult, but how would one return an XML string? 回答1: You could use return this.Content(xmlString, "text/xml"); to return a built XML string from an action. 回答2: For JSON/XML I have written an XML/JSON Action Filter that makes it very easy to tackle without handling

Must ASP.NET MVC Controller Methods Return ActionResult?

扶醉桌前 提交于 2019-11-26 15:37:02
问题 Being new to ASP.NET MVC, I've been wondering about the signature of Controller methods. In all the examples I've seen, they always seem to return ActionResult, even if they actually return a ViewResult instance or similar. Here's a commonly seen example: public ActionResult Index() { return this.View(); } In such a case, wouldn't it make more sense to declare the method as public ViewResult Index() , and get stronger type support? Experimentation indicates that this works, so it seems

Disable Session state per-request in ASP.Net MVC

Deadly 提交于 2019-11-26 15:04:33
I am creating an ActionResult in ASP.Net MVC to serve images. With Session state enabled, IIS will only handle one request at a time from the same user. (This is true not just in MVC.) Therefore, on a page with multiple images calling back to this Action, only one image request can be handled at a time. It's synchronous. I'd like this image Action to be asynchronous -- I'd like multiple image requests to each execute without needing the previous one to complete. (If the images were just static files, IIS would serve them up this way.) So, I'd like to disable Session just for calls to that

In MVC, how do I return a string result?

做~自己de王妃 提交于 2019-11-26 14:53:52
In my AJAX call, I want to return a string value back to the calling page. Should I use ActionResult or just return a string? swilliams You can just use the ContentResult to return a plain string: public ActionResult Temp() { return Content("Hi there!"); } ContentResult by default returns a text/plain as its contentType . This is overloadable so you can also do: return Content("<xml>This is poorly formatted xml.</xml>", "text/xml"); You can also just return string if you know that's the only thing the method will ever return. For example: public string MyActionName() { return "Hi there!"; }