maztt
maztt

Reputation: 12294

asp.net mvc razor getting id with post

how can i get the querystring id in there? is there any way

@using (Html.BeginForm("InformVendor", "Procurement",new {id="querystring Mode = "Inform" }, FormMethod.Post))
{
<tr>
    <td>
          @Html.DropDownListFor(m=>m.VendorId,new MultiSelectList(Model.VendorDropdownlist, "CustomerId", "ContactName"))   
     </td>
    <td>
          @Html.CheckBoxFor(m => m.IsEmail)
   </td>        
</tr>
<tr>
    <td>
         <input type="submit" id="btnsubmit" value="Nominate Vendor" />
    </td>
    <td></td>
</tr>
}

Upvotes: 0

Views: 1847

Answers (2)

hutchonoid
hutchonoid

Reputation: 33305

If you add the Id to your view model and render it as a hidden field.

@Html.HiddenFor(m => m.Id)

You will be able to retrieve it like this instead of using the querystring.

public ActionResult InformVendor(AViewModel model)
{
   var Id = model.Id;
}

Upvotes: 1

PlTaylor
PlTaylor

Reputation: 7515

The easiest way is to have your id field be hidden. This way the user doesn't see the ID field but your post back controller does.

@Html.HiddenFor(x => x.YourID)

Upvotes: 1

Related Questions