Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form which have one
C#
@using (Html.BeginForm("Details", "Home", FormMethod.Post))
    {
 <div class="FormContainer">
                
                    <table>
                        <tr>
                            <td class="Label">
                                @Html.Label("*Name of District")
                            </td>

                            <td>
                                
                                <div class="ddl1">
                                    @Html.Partial("_District")
                                   
                                </div>
                               

                            </td>
                        </tr>

                        <tr>
                            <td class="Label">
                                @Html.Label("*Name of Tehsil")
                            </td>

                            <td>
                                <div id="tehsil" class="ddl2">
                                    @Html.Partial("_Tehsil")
                                </div>
                            </td>
                        </tr>

                        <tr>
                            <td class="Label">
                                @Html.Label("*Name of Sub Tehsil")
                            </td>

                            <td>
                                <div id="Subtehsil">@Html.Partial("_SubTehsil", Model)</div>
                                
                            </td>
                        </tr>

                        <tr>
                            <td class="Label">
                                @Html.Label(" Village")
                            </td>
                            <td class="txbox">
                                @Html.TextBox("Village", null, new { @class = "txtbox" })
                            </td>
                        </tr>

                        <tr>
                            <td class="Label">
                                @Html.Label("*Name of Applicant")
                            </td>
                            <td class="txbox">
                                @Html.TextBox("NameOfApplicant", null, new { @class = "txtbox" })
                            </td>
                        </tr>

                        <tr>
                            <td class="Label">
                                @Html.Label("*Name of Land Owners / Owners")
                            </td>
                            <td class="txbox">
                                @Html.TextBox("NameOfLandOwners", null, new { @class = "txtbox" })
                            </td>
                        </tr>
</table>
}</div>


and in _District , _tehsil, _subtehsil partial view i have following

Quote:
C#
</blockquote>



@using (Ajax.BeginForm("Selecttehsil", "Home", new AjaxOptions { UpdateTargetId = "tehsil" }))
{

    @Html.DropDownListFor(m => m.SelectedDistrictId, 
                        new SelectList(Model.Districts, "DistrictId", "DistrictName"), 
                        "----Select District----", 
                        new { @class = "ddl" }
    )
 
}

<script type="text/javascript">
   
        $('#SelectedDistrictId').change(function () {
            $(this).parents('form').submit();
          
        });
   
</script>


_tehsil partial view

C#
@if (Model.Tehsils != null && Model.Tehsils.Count() > 0)
{ 
using (Ajax.BeginForm("Selectsubtehsil", "Home", new AjaxOptions { UpdateTargetId = "Subtehsil" }))
{    
    @Html.HiddenFor(m => m.SelectedDistrictId)
    @Html.DropDownListFor(m => m.SelectedTehsilId, new SelectList(Model.Tehsils, "TehsilId", "TehsilName"), "----Select Tehsil-----", new {@class = "ddl" })
}

}
<script type="text/javascript">
    $('#SelectedTehsilId').change(function () {
        $(this).parents('form').submit();
     
    });
</script>


_subtehsil Partial view

C#
@if (Model.SubTehsils != null && Model.SubTehsils.Count()>0)
{ 
    @Html.DropDownList("SubTehsils", new SelectList(Model.SubTehsils, "SubTehsilId", "SubTehsilName"), "----Select SubTehsil---", new { @class = "ddl"})
}


when i select an item from dropdownlist it get posted to "Details" action method which i want it to do when i click on submit button. Please tell me a way out here.
Posted
Updated 15-Jul-15 22:02pm
v2

1 solution

The code that is doing the submit is

$('#SelectedDistrictId').change(function () {
    $(this).parents('form').submit();

});

You have a similar script for SelectedTehsilId. If you don't want those drop downs to trigger a form submission then remove that code for that dropdown.
 
Share this answer
 
Comments
lokopi.nagar 16-Jul-15 4:14am    
Then how i am going to connect those drop down lists?
F-ES Sitecore 16-Jul-15 4:19am    
Put a submit button on the form instead and the user will click it.
lokopi.nagar 16-Jul-15 4:40am    
putting a button for DDL is not the requirement can i have something which only submit the ddl's not the whole form. cani add something to parents("HERE").submit();
F-ES Sitecore 16-Jul-15 4:47am    
You can't select what parts of the form to submit. If you're not interested in the other bits of form data then just ignore them.
lokopi.nagar 16-Jul-15 4:57am    
I already have a submit button on my form and i want others fields too any solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900