如何更改ASP.NET MVC控制器返回的ContentType(的ActionResult) [英] How to change returned ContentType in ASP.NET MVC controller (ActionResult)

查看:1415
本文介绍了如何更改ASP.NET MVC控制器返回的ContentType(的ActionResult)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ASP.NET MVC控制器命名的字典,方法ControlsLangJsFile。
方法返回视图用户控件(ASCX),它包含JavaScript变量。

I have ASP.NET MVC controller named dictionary with method ControlsLangJsFile. Method returns view of users control (ASCX) which contain JavaScript variables.

当我把它叫做返回变量与解析字符串,但内容类型是HTML /文本的方法。它应该是:应用程序/ x-的JavaScript

When i call the method it returns variables with parsed strings, but Content Type is html/text. It should be: application/x-javascript

public ActionResult ControlsLangJsFile()
    {
        return View("~/Views/Dictionary/ControlsLangJsFile.ascx",);
    }

我如何实现这一目标?

How do i achieve this?

推荐答案

用户控制不接受的ContentType =文/ XML

Users control doesn't accept ContentType="text/xml"

解决方案:

public ActionResult ControlsLangJsFile()
    {
        Response.ContentType = "text/javascript";
        return View("~/Views/Dictionary/ControlsLangJsFile.ascx");
    }

这篇关于如何更改ASP.NET MVC控制器返回的ContentType(的ActionResult)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆