[英]asp.net MVC. Can't use void method without redirect
I have a form and void post method. 我有一个表单和无效的帖子方法。
<form id="frm_loadFile" action="/Home/LoadFileWhithChanges" enctype="multipart/form-data" method="post" style="margin-top: 40px;">
<input type="file" style="width: 100%;" name="upload" value="Choose file"><br><br>
<input style="width: 115px;" type="submit" value="Upload">
</form>
[HttpPost]
public void LoadFileWhithChanges(HttpPostedFileBase upload)
{
if (upload == null)
{
Response.Write(@"<script language='javascript'>alert('No file')</script>");
Response.Flush();
Response.End();
return;
}
else
{
//...
Response.Write(@"<script language='javascript'>alert('All done')</script>");
Response.Flush();
Response.End();
return;
}
}
But when it calls Response.Write
after alert my page redirects 但是当它在警报后调用
Response.Write
时,我的页面重定向
I want stay on this page after response.write/
How can I do this? 我想在
response.write/
之后停留在该页面上response.write/
怎么做?
You are posting a form, and receive a response. 您正在发布表单,并收到响应。 It doesn't matter that your action is
void
. 你的行为
void
没关系。 The browser doesn't care how the response was generated on the server. 浏览器不在乎服务器上如何生成响应。 It's only course of action is to display the result.
唯一的行动就是显示结果。 If you want to stay in the same page, you should either:
如果要保留在同一页面上,则应该:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.