How to set contenttype in razor (CSHTML)?

前端 未结 3 572
孤街浪徒
孤街浪徒 2021-02-04 08:08

In classic ASP.NET Web Forms view engine, we can set the ContentType in the .aspx page to the desired type.

Is there a direct/recommended equivalent in Razor?

3条回答
  •  萌比男神i
    2021-02-04 09:12

    That will work I just tested it, you can also add the following line to your cshtml:

    Response.ContentType = "application/javascript";
    

    so that it looks something like this:

    @{
        ViewBag.Title = "Home Page";
        Response.ContentType = "application/javascript";
    }
    

    It just depends on where you prefer to make the change.

提交回复
热议问题