我需要一个控制器来处理文件上传。是否可以让处理程序直接将文本打印到页面而不是返回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");
}
答案 0 :(得分:0)
也许使用 ContentResult 可以胜任:
return new ContentResult() {
Content = "Testing",
ContentEncoding = System.Text.Encoding.UTF32,
ContentType = "text/plain"
};
答案 1 :(得分:0)
只需将action方法的返回类型更改为string并返回一个字符串即可。它看起来像这样:
public string ReturnString() { return "Just a string"; }