actionresult

How to construct a custom error json response using the Struts framework

折月煮酒 提交于 2019-11-29 07:54:35
I am working on creating a web application using struts. I want to send out a error JSON response like the below when the request URL is not well formed { “status”: 409, "code": 40924 “property”: “aggregation”, “message”: “aggregationId not specified.”, “moreInfo”: “https://www.iiitb-swn.com/docs/api/errors/40924” } I am already using the struts2-json plugin for serializing response objects using JSON. How should I go about sending JSON error responses. I can think of the below way of doing the same. Use an error response object in the action class and set all name required name value pairs

Using ActionForward with dynamic params in Struts 2

主宰稳场 提交于 2019-11-28 12:39:52
While migrating the application from Struts 1 to Struts 2 In some of the places, the same action class has been used for different type of views, based on the request params. For Example: if the createType is 1 means need to append one param or if the createType is 2 means need to append some more extra params, like that I need to pass dynamic params to some other action using ActionForward . struts-config.xml <action path="/CommonAction" type="com.example.CommonAction" scope="request"> <forward name="viewAction" path = "/ViewAction.do"/> </action> Action Class public class CreateAction

MVC Controller Using Response Stream

旧巷老猫 提交于 2019-11-28 08:37:28
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 Content(myData, "text/csv"); I could, I suppose, build a string, but since these files could be several

How to serve html file from another directory as ActionResult

有些话、适合烂在心里 提交于 2019-11-28 07:12:21
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? 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.UTF8Encoding(); var htm = System.IO.File.ReadAllText(Server.MapPath("/Solution/Html/") + "index.htm", encoding); byte[

How do I perform a secondary action (i.e. calculate fields) in ASP.NET MVC?

China☆狼群 提交于 2019-11-28 06:02:14
问题 I need to do some calculations on an ASP.NET MVC View, an action different than the form submission. I've tried various methods of passing the current Model on to a new controller action via an ActionLink, but the model doesn't appear to be passed. public ActionResult Calculate(MuralProject proj) { ProjectFormRepository db = new ProjectFormRepository(); List<Constant> constants = db.GetConstantsByFormType(FormTypeEnum.Murals); proj.Materials = new MuralMaterials(); proj.Materials.Volunteers =

Getting Result type in Interceptor

馋奶兔 提交于 2019-11-28 05:53:43
问题 I have Struts2 actions with different (HTML and JSON ) result types. They use common interceptor. If needed to intercept the request, how to return result based on given action result type? For example, my Action.ERROR forwards to JSP page. If action is JSON type I want to forward JSON error instead. 回答1: I have Struts2 actions with different (HTML and JSON ) result types. They use common interceptor. If need to intercept the request, how to return result based on given action result type?

How to construct a custom error json response using the Struts framework

扶醉桌前 提交于 2019-11-28 01:33:27
问题 I am working on creating a web application using struts. I want to send out a error JSON response like the below when the request URL is not well formed { “status”: 409, "code": 40924 “property”: “aggregation”, “message”: “aggregationId not specified.”, “moreInfo”: “https://www.iiitb-swn.com/docs/api/errors/40924” } I am already using the struts2-json plugin for serializing response objects using JSON. How should I go about sending JSON error responses. I can think of the below way of doing

Struts 2 - Redirecting to a correct action after authentication interceptor

扶醉桌前 提交于 2019-11-28 00:30:32
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-interceptor-ref name="secureStack"/> <global-results> <result name="login" type="redirect">dologin</result>

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

若如初见. 提交于 2019-11-27 18:05:46
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? You could use return this.Content(xmlString, "text/xml"); to return a built XML string from an action. For JSON/XML I have written an XML/JSON Action Filter that makes it very easy to tackle without handling special cases in your action handler (which is what you seem to be doing). Another way to do this is by using XDocument: using System.Xml.Linq; public XDocument ExportXml() {

How to pass List in Redirecttoaction

假装没事ソ 提交于 2019-11-27 15:32:11
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]); } } return RedirectToAction("Question", new { email = email, model = fadd.ToList() }); } My another Action