无法从调用视图操作INT他的asp.net的MVC方式 [英] Unable to call action from view int his way in asp.net mvc

查看:150
本文介绍了无法从调用视图操作INT他的asp.net的MVC方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发我的asp.net MVC应用程序的图片上传模块。对于我写code部分在我看来页面

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...

但无法调用动作后code得到发表。为什么要这样。有人可以帮我吗?

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

编辑:

     <% 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**

在萤火虫我得到了我的HTML该文本与彩色光:

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

推荐答案

我怀疑,当你发布站点有涉及虚拟目录。因此, /用户配置/ uploadfile 不再是一个正确的URL。为了避免这种情况,你应该永远难以code你的URL是这样的。我会使用HTML辅助建议你。

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.

所以:

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

这篇关于无法从调用视图操作INT他的asp.net的MVC方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆