1

我需要一个控制器来处理文件上传。是否可以让处理程序直接将文本打印到页面而不是 return view(); ?

public ActionResult Upload(HttpContext context)
        {
            HttpPostedFile file = context.Request.Files["fileData"];

            Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey;
            string userID = userGuid.ToString();

            string targetLocation = "D:\\inetpub\\wwwroot\\RTDOTNETMEMBER\\audio\\songs\\mp3\\" + userID + "\\" + file.FileName;

            file.SaveAs(targetLocation);

            Response.Write("Testing");
}
4

2 回答 2

0

只需将您的操作方法的返回类型更改为字符串并返回一个字符串。它看起来像这样:

    public string ReturnString()
    {
        return "Just a string";
    }
于 2012-05-16T21:49:41.757 回答
0

也许使用ContentResult可以完成这项工作:

return new ContentResult() { 
    Content = "Testing", 
    ContentEncoding = System.Text.Encoding.UTF32, 
    ContentType = "text/plain" 
};
于 2012-05-11T06:27:47.040 回答