locked
MVC Beta and Issues RRS feed

  • Question

  • User-1566710147 posted

    Hi there

    I'm exploring this MVC Beta and I found couple issues:

    1. In the Edit page for instance, I have EDIT button and CANCEL button. How do I handle this CANCEL when it clicks to differntiate between EDIT and CANCEL button? When it clicks to CANCEL button, it will go to Index view. The only way that I can think of is by putting A href="/case/index"  for the CANCEL but it's ugly one is button the other one is link.

    2. I am exploring FlexiGrid JQuery (http://www.codeproject.com/KB/aspnet/MVCFlexigrid.aspx) and so far it's ok if the grid has it's own page. But when I integrate with the edit form with couple fields and this FLEXIGRID the behaviour is funny. My question is there any grids that is easy and works nicely with MVC Beta version?

    I'm appreciated your comment.

    Thanks

     

    Friday, January 9, 2009 4:45 PM

Answers

  • User-109060882 posted

    Hi,

    I will attempt to answer your first question. I'm not familiar with the FlexiGrid or other grids, so I'm afraid I can't help with the second question.

    If you have only one button inside a form, there's no problem: All form submissions are treated the same way.

    If you have more than one button you can distinguish between them by giving each button a name:

        <input type="submit" name="SaveButton" value="Save data" />
        <input type="submit" name="CancelButton" value="Cancel and go back to main page" />

    In your controller action method you can add parameters named after the HTML input tag names:

        public ActionResult DoSomeStuff(string saveButton, string cancelButton, ... other parameters ...) { ... }

    If any value gets posted to one of those parameters, that means that button was the one that got clicked. The web browser will only post a value for the *one* button that got clicked. All other values will be null.

        if (saveButton != null) { /* do save logic */ }
        if (cancelButton != null) { /* do cancel logic */ }

    You can optionally check that the value of the string is exactly equal to the text of the "value" property in the HTML, but that is unnecessary. It's also a pain to deal with in case you ever change the text of the buttons, because then you'd have to update your controller as well. A very common case that would break down is if you decide to localize your application: Your controller would have to deal with every translation of the words.

    This is why I'd recommend just checking for not-null (or use String.IsNullOrEmpty()).

    Thanks,

    Eilon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 13, 2009 3:01 PM

All replies

  • User-109060882 posted

    Hi,

    I will attempt to answer your first question. I'm not familiar with the FlexiGrid or other grids, so I'm afraid I can't help with the second question.

    If you have only one button inside a form, there's no problem: All form submissions are treated the same way.

    If you have more than one button you can distinguish between them by giving each button a name:

        <input type="submit" name="SaveButton" value="Save data" />
        <input type="submit" name="CancelButton" value="Cancel and go back to main page" />

    In your controller action method you can add parameters named after the HTML input tag names:

        public ActionResult DoSomeStuff(string saveButton, string cancelButton, ... other parameters ...) { ... }

    If any value gets posted to one of those parameters, that means that button was the one that got clicked. The web browser will only post a value for the *one* button that got clicked. All other values will be null.

        if (saveButton != null) { /* do save logic */ }
        if (cancelButton != null) { /* do cancel logic */ }

    You can optionally check that the value of the string is exactly equal to the text of the "value" property in the HTML, but that is unnecessary. It's also a pain to deal with in case you ever change the text of the buttons, because then you'd have to update your controller as well. A very common case that would break down is if you decide to localize your application: Your controller would have to deal with every translation of the words.

    This is why I'd recommend just checking for not-null (or use String.IsNullOrEmpty()).

    Thanks,

    Eilon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 13, 2009 3:01 PM
  • User-1566710147 posted

    Thanks for this I will try this approach.

    Regarding the "grid", do you have any other recommendation? What I want to do is sorting and paging?  

    Wednesday, January 14, 2009 5:55 AM
  • User-109060882 posted

    Hi again,

    I think if you try to start another discussion thread specifically about grid solutions for MVC you will get more responses. I think I've seen people discuss grids once or twice here. Alternatively, a quick web search might yield some results as well. There are several companies out there already working on controls specifically for ASP.NET MVC.

    Thanks,

    Eilon

    Thursday, January 15, 2009 12:33 PM