Asp.net mvc 2 控制器中未调用ActionResult
未调用控制器中的ActionResult。设置断点表明未命中ActionResult文件上载 下面的视图和控制器代码:FileUpload.aspx/FileUploadController.cs:Asp.net mvc 2 控制器中未调用ActionResult,asp.net-mvc-2,Asp.net Mvc 2,未调用控制器中的ActionResult。设置断点表明未命中ActionResult文件上载 下面的视图和控制器代码:FileUpload.aspx/FileUploadController.cs: <% using (Html.BeginForm("fileUpload", "FileUpload", FormMethod.Post, new { enctype = "multipart/form-data" })) {%>
<% using (Html.BeginForm("fileUpload", "FileUpload",
FormMethod.Post, new { enctype = "multipart/form-data" }))
{%>
<input type="file" name="file" id="file" />
<input type="submit" name="Submit" value="Upload File" />
<span style="color: red; font-weight: bold">
<%=TempData["UploadValidationMessage_Failure"]%>
</span><span style="color: Green; font-weight: bold">
<%=TempData["UploadValidationMessage_Success"]%>
</span>
<%} %>
/// <summary>
/// n/a
/// </summary>
/// <returns>set FileUpload view return value</returns>
public ActionResult Index()
{
return View("FileUpload");
}
/// <summary>
/// Uploads the file and store it in ~\Uploads directory.
/// </summary>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult fileUpload(HttpPostedFileBase file)
{
if (file.ContentLength > 0 & isXLSXFile > 0)
{
string filePath = Path.Combine(
Server.MapPath("~/Uploads"),
Path.GetFileName("ExcelFileUpload.xlsx")); // save as new filename
try
{
file.SaveAs(filePath);
TempData["UploadValidationMessage_Success"] = "File upload succeeded";
return View();
}
catch (Exception e)
{
TempData["UploadValidationMessage_Failure"] = "Failed to upload the file " + e.ToString();
return View();
}
}
else
{
TempData["UploadValidationMessage_Failure"] = "Filename missing or filename extension is not .xlsx";
return View();
}
}
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
}
你能告诉我们更多的细节吗?另外,请包括在global.asax中找到的路由,这可能是由路由问题引起的。public static void registerOutesRouteCollection routes{routes.IgnoreRoute{resource}.axd/{*pathInfo};routes.maprote Default,//路由名称{controller}.aspx/{action}/{id},//带有参数new{controller=Home,action=Index,id=urlparmeter.Optional}//参数默认值;routes.MapRoute Root,,new{controller=Home,action=Index,id=};}你需要更多的细节吗?好的,问题解决了。原来是我对Site.Master文件所做的更改有问题。Inspect元素显示标记不是由Html.BeginForm生成的。在Stackoverflow->上发现了类似的问题。啊,我怎么也想不到。请回答你自己的问题并将其标记为答案。谢谢