2010-08-18 45 views
0

我不假设任何人对此有所了解?该文档是可怕的和远远过时(我能找到的最好的资源是2006年)。MonoRail文件上传

我的形式:

<form action="DoCreate.rails" method="post"> 

    ${FormHelper.LabelFor("master.Name", "Name", {"class":"label"})} 
    ${FormHelper.TextField("master.Name", {"class":"text-input full-width"})} 

    ${FormHelper.LabelFor("masterFile", "File", {"class":"label"})} 
    <input type="file" id="masterFile" name="masterFile" /> 

    <div class="edit-controls"><a href="/Master/Index.rails">Back</a> | <input type="submit" value="Create" /></div> 
</form> 

我的控制器动作:

public void DoCreate(Master master, HttpPostedFile masterFile) 
    { 
     try 
     { 
      Bus.Master.Create(master); 

      if (masterFile != null) 
      { 
       masterFile.SaveAs(@"C:\" + masterFile.FileName); 
      } 

      RedirectToAction("Index"); 
     } 
     catch (ApplicationException e) 
     { 
      PropertyBag["error"] = e.Message + "<br />" + e.StackTrace; 
      Create(); 
      RenderView("Create"); 
     } 
    } 

我跟着this guide也无济于事,因为它不会告诉你什么实际的HTML页面上做。

+0

我在这里错过了实际的问题。这里有什么问题?作为附注,我们不建议通过POST调用来渲染视图。这将与用户的浏览历史记录混淆。最好是重定向(在你的情况下为“创建”操作),这样用户的浏览器就会发布一个带有表单的网页的新GET请求。 – 2010-08-18 11:56:36

+0

对不起,实际的问题是上传不起作用,我不确定HTML页面应该包含什么,因为MonoRail似乎已经摆脱了文件上传助手。如果我试图调用它,我得到错误“无法转换参数,因为与param相关的节点不是叶节点。参数主父节点:根”。 – Kezzer 2010-08-18 12:00:24

回答

2

看起来问题在于表单的声明。 上传文件时,应该使用添加另一个属性到表单元素:enctype="multipart/form-data"