This is a part of my view :
<% using (Html.BeginForm())
{ %>
<input type="checkbox" name="ali" value="123" />
<%: Html.CheckBox("ali1") %>
<a href='<%:Url.Action("DeleteSelected", "Product", new { @ShopID = ViewBag.shopIDempty } ) %>'>dddd</a>
<input type="submit" onclick='<%: Url.Action("DeleteSelected", "Product", new { @ShopID = ViewBag.shopIDempty } ) %>' />
<%} %>
and this the controller :
public ActionResult DeleteSelected(FormCollection collection, int ShopID)
{
var t = collection.GetValue("ali");
var t2 = collection["ali"];
var selectCB11 = collection.GetValue("ali");
var t1 = collection.GetValue("ali1");
var t21 = collection["ali1"];
var selectCB121 = collection.GetValue("ali1");
//...
}
But nothing passes to my variables and all of them are null always. What is wrong?
Clicking a link will never post back to the server, or redirecting client-side from a submit button will also not cause the postback. Any input values like the checkbox will never be sent to the server. You need to use a form with the submit button, and let the submit naturally postback to the server.
Or, you can use JQuery’s $.ajax to create a JavaScript post statement to do this asynchronously, like these examples.