How can I get a handle on which button fired "submit" from MVC controller?

3 posts, 0 answers
  1. Warner
    Warner avatar
    4 posts
    Member since:
    Feb 2014

    Posted 30 Apr 2015 Link to this post

    Simple use case; a pretty common one I would assume:

    I have more than one kendo button displayed within an MVC view.  When one of the buttons fires the "submit" event, I want to be able to grab a handle on which button fired the submit from within my controller.  I had assumed that you could assign "button" to the name attribute and then determine through the button's "value" property which button fired the event.

    The controller signature would look like this: 

    [HttpPost]

    public ActionResult(string button) { determine course of action based on button's value property...}

    I'm actually taken back at the fact that one of the most fundamental uses of the input button type is simply not given any means to do this simply. Of course, I could be blind and missing something, but I've searched forums and Telerik documentation and found little if anything on performing this basic task.

     

    Thanks!

     


        

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 05 May 2015 Link to this post

    Hello,

    Using input type submit or button element is not supported. The scenario can be implemented by using the select event to set the value to a hidden input and submit the form e.g.
    @using (Html.BeginForm())
    {
        ...
        <input type="hidden" id="button" name="button"/>
    }
    function onSelect(e) {
        var text = this.current().text();
        $("#button").val(text);
        $("form").submit();
    }


    Regards,
    Daniel
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Warner
    Warner avatar
    4 posts
    Member since:
    Feb 2014

    Posted 05 May 2015 in reply to Daniel Link to this post

    Thank you!  That's pretty much the work-around I used.

    Somewhere in the future, you may want this functionality incorporated into the actual control. After all, it is a common use case for buttons.

Back to Top