Unable to call action from view int his way in asp.net mvc

╄→гoц情女王★ 提交于 2020-01-06 08:33:49

问题


I am developing the image upload module for my asp.net mvc application. for that I write code partially in my view page as

//Other html code...
 <div id="popuup_div" class="popup_msg">
  <form action="/UserProfile/uploadfile" method="post" enctype="multipart/form-data">
    <%= Html.Hidden("userIdForFile",Model.UserId) %>
   <p>
     <label for="ProfilePhoto"><%= Resources.Global.ProfilePhoto %>:</label>
     <input type="file" name="pPhoto"  />
   </p>
   <input type="submit" value="upload" /> |<input type="button" value="close" onclick="javascript:$('#popuup_div').hide();" />    
  </form>
</div>

//Other html code...

But unable to call the action after code get published . why should be this . can somebody help me ?

Edited:

     <% using (Html.BeginForm("uploadfile", "UserProfile", FormMethod.Post, new { id = "testform", enctype = "multipart/form-data" }))
             {%>
            <%= Html.Hidden("userIdForFile", Model.UserId)%>
           <p>
             <label for="ProfilePhoto"><%= Resources.Global.ProfilePhoto%>:</label>
             <input type="file" name="pPhoto"  />
           </p>
           <input type="submit" value="upload" /> |<input type="button" value="close" onclick="javascript:$('#popuup_div').hide();" />    
 <% } %>


    **Edited**

In firebug i got this text of my HTML with light colored :


回答1:


I suspect that when you publish the site there is a virtual directory involved. So /UserProfile/uploadfile is no longer a correct url. To avoid this you should never hardcode your urls like this. I would recommend you using HTML helpers.

So:

<% using (Html.BeginForm("uploadfile", "UserProfile", null, FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
    ...
<% } %>


来源:https://stackoverflow.com/questions/4690055/unable-to-call-action-from-view-int-his-way-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!