actionresult

Can you apply an ActionFilter in ASP.NET-MVC on EVERY action

六眼飞鱼酱① 提交于 2019-12-04 22:08:16
问题 I want to apply an ActionFilter in ASP.NET MVC to EVERY action I have in my application - on every controller. Is there a way to do this without applying it to every single ActionResult method ? 回答1: Yes, you can do this but it's not the way it works out of the box. I did the following: Create a base controller class and have all of your controllers inherit from it Create an action filter attribute and have it inherit from FilterAttribute and IActionFilter Decorate your base controller class

JSON exception error while output using Struts 2

我只是一个虾纸丫 提交于 2019-12-04 16:56:48
I am getting the JSON Exception error when I am executing the result into the browser like the following: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ProductDetails.ISN, no session or session was closed org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:209) org.apache.struts2

What are all the ASP.Net MVC Action Results?

走远了吗. 提交于 2019-12-04 16:42:03
问题 Is there a list of all the ASP.Net MVC action results and their uses? I've been busily using ActionResult for almost everything but I know that's not correct and that I should be using more specific action results. I've Googled this but cannot find a list. We've just bought the Wrox book but it's more than a week away from delivery and I'd like to read up on this well before then. Can you also roll your own and is that documented somewhere? 回答1: If you open System.Web.Mvc using Reflector, you

ASP.NET MVC: How to covert an ActionResult to string?

蹲街弑〆低调 提交于 2019-12-04 11:06:30
问题 I would like to take an existing action method, render its return value to a string and ship it as a JSON for a response to an AJAX request. To do this, I need to render an ActionResult to a string. How do i do this? We have the opposite where we can convert a string to an ActionResult by using this.Content(). Update The existing and 1st action method returns a type ActionResult but it really returns a ViewResult to respond to HTTP post request. I have a 2nd action method (my facade) that

Struts2 jquery Plugin responds to ajax requests with HTML of the entire page

心不动则不痛 提交于 2019-12-03 17:09:41
I am trying to use the Struts2 jquery plugin for ajax requests on some of my forms, but I am having an issue with the response to the page. The struts action is validated and executed properly, but when jquery gets a response, it sets the response as the HTML of the entire page... It is putting the response in the correct place, but it is not responding with the right thing at all... Here is the jsp form: <%@ tag language="java" pageEncoding="UTF-8"%> <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> <%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="sj" uri="/struts

What are all the ASP.Net MVC Action Results?

吃可爱长大的小学妹 提交于 2019-12-03 10:38:49
Is there a list of all the ASP.Net MVC action results and their uses? I've been busily using ActionResult for almost everything but I know that's not correct and that I should be using more specific action results. I've Googled this but cannot find a list. We've just bought the Wrox book but it's more than a week away from delivery and I'd like to read up on this well before then. Can you also roll your own and is that documented somewhere? If you open System.Web.Mvc using Reflector , you will see that there are several derived types that inherit from the abstract class ActionResult. They are:

How to unit test an ActionResult that returns a ContentResult?

我只是一个虾纸丫 提交于 2019-12-03 08:02:24
问题 I want to unit test the following ASP.NET MVC controller Index action. What do I replace the actual parameter in the assert below (stubbed with ?). using System.Web.Mvc; namespace MvcApplication1.Controllers { public class StatusController : Controller { public ActionResult Index() { return Content("Hello World!"); } } } [TestMethod] public void TestMethod1() { // Arrange var controller = CreateStatusController(); // Act var result = controller.Index(); // Assert Assert.AreEqual( "Hello World

What's the point of ActionResult return type?

梦想与她 提交于 2019-12-03 05:58:43
问题 What is the point of an action returning ActionResult? 回答1: Returning an ActionResult instead of "just doing whatever the ActionResult is doing" (i.e. using Response.Redirect directly or trying to render out a View through the Response OutputStream directly) gives you one really nice advantage: Unit Testing is really easy on that, especially since you normally do not need a web server to unit test MVC Projects. Addendum: As an example for a redirect: If you do return Redirect(newUrl); in your

MVC3 - Ajax loading icon

纵然是瞬间 提交于 2019-12-02 20:56:57
I would like to show an AJAX loading icon during an ActionResult request that can take a few seconds to process. What is the best approach to accomplished this? I only want to display the icon after the built it validation passes (I am using MVC3, EF Code First, so the validation is automatically put on the page). There may be further validation/exceptions during the ActionResult, in which case a message is displayed to the user, and I'd then want the loading icon to disappear again. Define your link as an Ajax action link and specify the ID of a spinning GIF somewhere on your page. <div id=

Getting JSON object from Java in Struts 2

空扰寡人 提交于 2019-12-02 12:56:11
问题 I am trying to get response text from java server using getJSON jQuery method. Although, I can get response data when the java class is simple format ( String , List and Map ), I could not get success data when using other java object. the following Java class is simple type and get access success data and work package com.awitd.framework.action; import com.opensymphony.xwork2.Action; public class getAllJson implements Action{ private String data; public String getData() { return data; }