我无法弄清楚我做错了什么。 我的项目启动时带有索引视图,该视图发布到fileUpload操作。 从fileUpload操作中,控制器中的另一个方法称为changeText(),并且在changeText()的末尾有一个对结果(文本)的调用,它接受参数字符串。在Results()的末尾有一行返回View()到Results.cshtml。但是Results.cshtml没有加载。 只是想知道我是否遗漏了什么。
public ActionResult Index()
{
return View();
}
[HttpPost]
public void FileUpload(HttpPostedFileBase file)
{
Debug.WriteLine(file.FileName)
if (file != null)
{
var fileName = Path.GetFileName(file.FileName);
pathName = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
file.SaveAs(pathName);
}
changeText(txt);
}
public void changeText (string text)
{
ResultX(textChange);
}
public ActionResult ResultX(string text)
{
Debug.WriteLine("resultx action");
return View(text);
}
Thanks.
答案 0 :(得分:2)
这是您的代码应该是:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase file)
{
Debug.WriteLine(file.FileName)
if (file != null)
{
var fileName = Path.GetFileName(file.FileName);
pathName = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
file.SaveAs(pathName);
}
return changeText(txt);
}
public ActionResult changeText (string text)
{
return ResultX(textChange);
}
public ActionResult ResultX(string text)
{
return View("ResultX", text);
}
答案 1 :(得分:1)
您似乎并不理解行动的运作方式。首先,操作的返回类型确定向客户端发送的响应。返回void
意味着您将返回一个带有200状态代码的空响应正文。对于通过网络浏览器访问您网站的用户而言,这意味着一个完全空白的页面,这不是您想要的。
您想要的是使用ViewResult
返回ResultX.cshtml
。这意味着您的FileUpload
操作需要返回ViewResult
或更常见的ActionResult
。 ActionResult
是所有其他结果类型的基类,因此如果您以这种方式键入返回,则可以返回任何类型的结果,无论是ViewResult
,RedirectResult
,{ {1}}等等。
鉴于此,EmptyResult
和changeText
作为方法的存在是多余的。没有理由在三种不同的方法之间传递这一点,这些方法几乎都做同样的事情。只需ResultX
直接return View("ResultX", txt);
即可。但是,成功的帖子应遵循PRG(Post-Redirect-Get)模式,因此如果用户刷新页面,则不会重新提交表单。因此,您应确实返回成功的重定向,并在出错时返回原始FileUpload
视图。总而言之,这看起来像:
FileUpload
答案 2 :(得分:1)
我看不出所有这些方法的原因! 你的代码可以非常简单。
today=$(date +%Y%m%d)
echo "DataBase "$(date +%d/%m/%Y)>/jdb"$today".txt
du -s $(ls -l|grep ^d|awk '{print $9})|awk '{print $2" "$1" "}'>>/jdb"$today".txt
如果所有这些都不起作用,请确保您正在调用正确的视图