1

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?

2
  • What is the purpose of the submit button with a URL in it's onclick event handler? Commented Jan 18, 2013 at 16:05
  • Actually I have some pictures in a page. The user want to delete some of them. User selects some pictures with checkbox. There is a checkbox beside of each picture. then the must click the delete button. Now I want to send the selected checkbox to Delete action and delete pictures. How can I do that? Commented Jan 18, 2013 at 16:15

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.