[RESOLVED]jQuery form submit to same page – unexpected results

EntryF is the file that has all the code below including a break point on if (IsPost) {

The page is displayed with –Size– in the select.

When the user changes that to another option the jquery triggers, and I get logged out.

It should post back to the same page but never hits the break point.

Any suggestions?

<form class="horseform" method="post" action="~/Members/EntryF">
<select class="form-control" data-val="true" name="size" id="size">
        <option value="">--Size--</option>
            @foreach (var ss in shoesizes)
                { 
                <option value="@ss.sSize"  selected="@(ss.sSize == shoesizeold)" >@ss.sSize</option>
                }  
        </select>
        $('#size').change(function () {
            if (showbuttontorefresh == 1) {
                if ($(this).val() != '') {
                    $('[name=fservice]').val("584");
                    $('[name=action]').val("Refresh");
                    $("form").submit();

                    console.log(showbuttontorefresh);
                }
            }
        });

Hi wavemaster,

wavemaster

<form class="horseform" method="post" action="~/Members/EntryF">

From your description, I suppose the issue is that the form didn’t submit. Please try to modify your code as below:

@using (Html.BeginForm("CategoryChosen", "Test", FormMethod.Get)) {
    <fieldset>
        select class="form-control" data-val="true" name="size" id="size">
        <option value="">--Size--</option>
            @foreach (var ss in shoesizes)
                { 
                <option value="@ss.sSize"  selected="@(ss.sSize == shoesizeold)" >@ss.sSize</option>
                }  
        </select>
    </fieldset>
}

Here is a tutorial, you could refer to it.

http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc

If you have any questions about my reply, please let me know freely.

Best Regards,
Dillion

Leave a Reply