Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 MVC3表单过帐,带有值和文件_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 MVC3表单过帐,带有值和文件

Asp.net mvc 3 MVC3表单过帐,带有值和文件,asp.net-mvc-3,Asp.net Mvc 3,我是MVC3新手,我想创建一个带有输入列和文件上传的表单 当我试图同时做这两件事时,问题就来了 这是我的密码 ... [HttpPost] public ActionResult About(string inputStr) { string local = inputStr; string[] word = inputStr.Split(':'); return View(); } [HttpPost]

我是MVC3新手,我想创建一个带有输入列和文件上传的表单

当我试图同时做这两件事时,问题就来了

这是我的密码

...
    [HttpPost]
    public ActionResult About(string inputStr)
    {
        string local = inputStr;
        string[] word = inputStr.Split(':');
        return View();
    }
    [HttpPost]
    public ActionResult GetFile(string inputStr, HttpPostedFileBase file)
    {
        string filename = file.FileName;
        return RedirectToAction("About");
    }
这两个是我的控制器

@using (Html.BeginForm("GetFile", "Home", (new { inputStr = "111" }), FormMethod.Post, new { enctype = "multipart/form-data" })){
<div class="editor">

  <input type="file" name="file" />
  <input type="submit" value="OK" id="submitFile" class="testingSubmit"/>

</div>
}
在这里,我试图做的是获取用户输入并将其放在字符串totalString上。 我可以使用$.post将totalString发布到控制器

我的问题是: 1.我走对了吗?i、 e.是否可以在一个职位上同时完成这两项任务? 2.如果没有,可能的解决方案是什么


非常感谢您的关注,希望这可以解决

我认为这样做应该行得通:

 @using (Html.BeginForm("GetFile", "Home", (new { inputStr = "111" }), FormMethod.Post, new { @id = "frmGetFile", enctype = "multipart/form-data" })){
    <div class="editor">

      <input type="file" name="file" />
      <input type="hidden" name="totalString" id="totalString"/>
      <input type="submit" value="OK" id="submitFile" onclick="submitGetFileForm()" class="testingSubmit"/>

    </div>
    }
控制器:

[HttpPost]
    public ActionResult GetFile(string totalString, HttpPostedFileBase file)
    {
        // your action logic..
    }

你可能会考虑把这个贴在你的建议上,谢谢埃里克,但是我可以知道区别吗?这两个站点都是重叠的,但是这一点往往会有问题,比如为什么我的代码不起作用,而CoDeVIEW有问题,比如我的代码是最好的方法吗?我能做些什么使它更好?这差别不大,但是如果你在这里没有得到答案,试试那边。这很有帮助!谢谢兄弟!
function submitGetFileForm(e)
{
   e.preventDefault();
   var total = //build your total string here
   $('#totalString').val(total);
   $('#frmGetFile').submit();
}
[HttpPost]
    public ActionResult GetFile(string totalString, HttpPostedFileBase file)
    {
        // your action logic..
    }