Pass multiple parameters in Html.BeginForm MVC4 controller action

前端 未结 4 1727
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 15:26

I have something like this:

   public ActionResult ImageReplace(int imgid,HttpPostedFileBase file)
    {
        string keyword = imgid.ToString();
        .         


        
相关标签:
4条回答
  • 2020-12-29 15:38

    You can also pass imgid as a field in the form, something like:

    @model Models.MemberData
    @using (Html.BeginForm("ImageReplace", "Member", FormMethod.Post,
            new { enctype = "multipart/form-data" }))
    { 
       @Html.HiddenFor(x => x.Id)
       <input type="file" name="file" id="file" value="Choose Photo"  /> 
       <input type="submit" name="submit" value="Submit" />
    }
    
    0 讨论(0)
  • 2020-12-29 15:47

    Use this overload, which allows you to distinguish between route values and HTML attribtues:

    @using (Html.BeginForm(
            "ImageReplace", "Member", 
            new { imgid = @Model.Id }, 
            FormMethod.Post,
            new { enctype = "multipart/form-data" }))
    { 
        <input type="file" name="file" id="file" value="Choose Photo"  /> 
        <input type="submit" name="submit" value="Submit" />
    }
    
    0 讨论(0)
  • 2020-12-29 15:48

    Use this:

          @using (Html.BeginForm("ImageReplace", "Member",   
          new { imgid = @Model.Id },   FormMethod.Post,
      new { enctype = "multipart/form-data" }))
    
    0 讨论(0)
  • 2020-12-29 15:57
        @using (Html.BeginForm("Search", "Orders", FormMethod.Post, htmlAttributes: new { id = "example-form", @class = "app-search" }))
           {
    
               <input type="text" class="form-control" name="OrderNo" style="max-width:100% !important" placeholder="Search OrderNo"> 
                <a class="srh-btn">
                 <i class="ti-close"></i>
                </a>
               </input>
    
           }
    
      public ActionResult Search(FormCollection form)
            {
                string Orderno = form["OrderNo"];
                int orderno = Convert.ToInt32(Orderno);
    
                return View(orderno );
            }
    
    0 讨论(0)
提交回复
热议问题