ASP.NET MVC:如何隐蔽一个ActionResult字符串? [英] ASP.NET MVC: How to covert an ActionResult to string?
问题描述
我想利用现有的操作方法,它的返回值呈现为字符串,并运送它作为一个AJAX请求的响应一个JSON。
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.
要做到这一点,我需要渲染一个ActionResult为字符串。我该怎么做呢?
To do this, I need to render an ActionResult to a string. How do i do this?
我们有相反的,我们可以通过使用this.Content()将字符串转换为一个ActionResult。
We have the opposite where we can convert a string to an ActionResult by using this.Content().
更新
现有和第一操作方法返回一个类型的ActionResult,但它确实返回的ViewResult对HTTP POST请求作出回应。我有第二个动作方法(我的门面),返回来响应AJAX请求一个JsonResult。我想这第二个操作方法使用第一操作方法来呈现HTML。
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 returns a JsonResult that responds to AJAX requests. I want this 2nd action method to use the 1st action method to render the HTML.
在事物的宏伟计划,我想一个ActionResult(从操作方法产生的)检索,不仅由一个标准的HTTP职位,但也通过正面的操作方法的AJAX请求(第2操作方法)。这样一来,我作为一个开发者,必须使用HTTP POST或AJAX检索页面的渲染选择。
In the grand scheme of things, I want an ActionResult (generated from an action method) retrievable not only by a standard HTTP post, but also by an AJAX request via a facade action method (the 2nd action method). This way, I, as a developer, have the choice of using an HTTP Post or AJAX to retrieve the rendering of a page.
对不起,我试图使此更新尽可能短。谢谢你。
Sorry i tried to make this update as short as possible. Thanks.
推荐答案
您是否正在寻找4号或6波纹管?
Are you looking for number 4 or 6 bellow?
文本这里:
理解的行为结果
一个控制器动作返回一种叫做动作的结果。一个动作的结果是什么样的控制器操作响应浏览器请求返回。
A controller action returns something called an action result. An action result is what a controller action returns in response to a browser request.
ASP.NET MVC框架支持多种类型的操作结果,包括:
The ASP.NET MVC framework supports several types of action results including:
- 的ViewResult - 再presents HTML和标记
- EmptyResult - 再presents没有结果
- RedirectResult - 重新presents重定向到一个新的URL 。
- JsonResult - 再presents可以在AJAX应用程序中使用的JavaScript对象符号结果
- JavaScriptResult - 重新presents一个JavaScript脚本 。
- ContentResult类型 - 再presents文本结果
- FileContentResult - 重新presents一个可下载的文件(二进制内容) 。
- FilePathResult - 重新presents一个可下载的文件(路径) 。
- FileStreamResult - 重新presents一个可下载的文件(文件流) 。
所有这些行动的结果从基本的ActionResult类继承。
All of these action results inherit from the base ActionResult class.
这篇关于ASP.NET MVC:如何隐蔽一个ActionResult字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!