Current Solution
所以,我有非常相似的东西
[HttpPost]
public ActionResult Upload()
{
var length = Request.ContentLength;
var bytes = new byte[length];
if (Request.Files != null )
{
if (Request.Files.Count > 0)
{
var successJson1 = new {success = true};
return Json(successJson1, "text/html");
}
}
...
return Json(successJson2,"text/html");
}
Unit testable solution?
我想要这样的东西:
[HttpPost]
public ActionResult Upload(HttpRequestBase request)
{
var length = request.ContentLength;
var bytes = new byte[length];
if (request.Files != null )
{
if (request.Files.Count > 0)
{
var successJson1 = new {success = true};
return Json(successJson1);
}
}
return Json(failJson1);
}
然而,这失败了, 令人烦恼,因为我可以做一个模克 从基级,并使用它。
Notes
- I am aware this is not a good way to parse a form/upload and would like to say other things are going on here (namely that this upload can be a form or an xmlhttprequest - the action does not know which).
- Other ways to make "Request" unit testable would also be awesome.