HTML.BeginForm不会调用正确的操作

时间:2014-05-13 10:00:32

标签: asp.net-mvc-4

我在Edit.chtml中有这个部分看起来像

@using (@Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
<article class="SearchBoxCon clearfix">
                        @if (Model.Entity.Document == null)
                        {
                            using (Html.BeginForm("AudioUpload", "Noun", FormMethod.Post, new { enctype = "multipart/form-data", NounId = Model.Entity.Id }))
                            {
                                <article class="BtnCon">

                                    <article class="BrowseBtn">
                                        <input type="file" value="Browse" name="file">
                                    </article>
                                    <article class="BrowseUpload">
                                        <input type="submit" id="AudioUpload" value="AudioUpload">
                                    </article>

                                </article>


                            }

                        }
                        else
                        {
                            <article class="inputBTn">
                                <input type="submit" value="Play">
                                <input type="submit" value="Delete">
                            </article>
                        }
                    </article>

                <article class="inputBTn">
                    <input type="submit" value="Save">
                </article>
                <!-- submit btn ends here -->
                @Html.ActionLink("Back to List", "Index", "Noun/Index", null, new { @class = "BackList" })
            </article>


}

浏览并上传文件后,点击上传即可点击编辑发布操作,而不是看起来像

的uploadaudio
 [HttpPost]
        public ActionResult AudioUpload(HttpPostedFileBase file , int NounId )
        {

2 个答案:

答案 0 :(得分:0)

[ActionName(&#34;编辑&#34;)]将属性放在您的操作方法上它将起作用

[HttpPost, ActionName("Edit")]
    public ActionResult AudioUpload(HttpPostedFileBase file , int NounId )
    {
如果您的视图名称是Edit.cshtml

,请使用此类代码

答案 1 :(得分:0)

试试这个,

@if (Model.Entity.Document == null)
 {
  using (Html.BeginForm("AudioUpload", "Noun", FormMethod.Post, new { enctype = "multipart/form-data", NounId = Model.Entity.Id,Id="frmAudioUpload" }))
  {<article class="BtnCon">

    <article class="BrowseBtn">
    <input type="file" value="Browse" name="file">
    </article>
    <article class="BrowseUpload">
    <input type="button" id="AudioUpload" value="AudioUpload">
    </article>

    </article>
}}

<强>脚本

<script type="text/javascript">
    $(function(){
      $('#AudioUpload').click(function(){
        $('#frmAudioUpload').submit();
      });
    });
</script>