Dropdownlistfor Binding Problem On Edit in ASp.net MVC

Last Reply 4 days ago By dharmendr

Posted 11 days ago

hello,

I am not able to bind the selected value to dropdown on th etime of edit. I am Explaining my whole procedure I have One Textbox named Occupanytype,one another textbox named Tariff and dropdownlsist named secondaryOccupancy. To fill data in Occupanytype i use jquery autocomplete. I have writtten the code in source property of autocomplete. On selection of the data from Occupanytype,my textbox named Tariff will get filled and my dropdownlist will have items filled in it. After That i will select one item from Dropdownlist and will Save the Data.

Then on edit button i have to retrive the saved data .i ma getting proper data in textboxes but i am not able to get the selected item in my dropdownlist.. I am attaching the code and screenshot along with it Please have a look and prepare a demo regarding this so that i can use it ...i am Trying i since two week but i am not suceeding..

Design code:

<td width="30%">
    <%= Html.TextBoxFor(m => m.OccupancyType, new { id = "txtOccupancyType", style = "width:250px",onblur="ShowHideSecIII();", onkeypress = "return alphaNumSpaceOnlyMaster(event)"})%>
    <%=Html.Hidden("hdnOccupancySelected","")%>
    <%=Html.HiddenFor(m => m.OccupancyTypeId, new { id = "hdnOccupancyTypeCode" })%>
    <a class="infolarge"><span>Please enter the key words of the occupancy, in case of long
        term policy this shall be restricted to dwellings</span>
        <img alt="" src="<%= Url.Content("~/Content/Images/ToolTip.gif")%>" />
    </a>
</td>

javascript Code:

<script type="text/javascript">
$("#txtOccupancyType").autocomplete({
    minLength: 3,
    select: function (event, ui) {
        var occupancyType = document.getElementById("txtOccupancyType").value = ui.item.value;
        var occupancyTariff = document.getElementById("txtOccupancyTariff").value;
        var longtermtype = $("#ddlSelectLongTermPolicy").val();

        debugger;
        $.ajax({
            url: '<%=Url.Content("~/Fire/GetOccupancyTariff")%>', type: "POST",
            cache: false,
            data: { occupancyType: occupancyType, longtermtype: longtermtype },
            success: function (data) {
                document.getElementById("hdnOccupancySelected").value = occupancyType;
                if (document.getElementById("hdnOccupancySelected").value == "Storage of defined goods (storage in godown)") {

                    $('.ms-options').find('li:not(.optgroup)').filter('.selected').find('input[type="checkbox"]').trigger('click');
                    $("#goods_options").show();

                }
                else {
                    $("#goods_options").hide();
                }
                document.getElementById("txtOccupancyTariff").value = data.split('|')[0];
                document.getElementById("hdnOccupancyTariff").value = data;
                $('#txtOccupancyTariff').attr('disabled', 'disabled');
                ShowHideSecIII();
                $('#ddlClassOfConstruction').val('0');
                $('#ddlMaterialType').val('0');
                $('#ddlNoOfFloors').val('0');
                $('#ddlAgeOfBuilding').val('0');
            }
        });

        var Cover = document.getElementById('ddlSecondaryOccupancy');
        $.ajax(
{
url: '<%=Url.Content("~/Fire/GetSecondaryOccupancyType")%>', type: "POST",
dataType: "json",
async: false,
data: { occupancyType: occupancyType },
success: function (data) {
var dd = 10;
$.map(data, function (item) {

AddItem(Cover, item.OccuPancyTypeText, item.OccuPancyTypeId);
});
}
});
    },
    source: function (request, response) {
        var occupancyObj = document.getElementById("txtOccupancyType");
        var errorSpanId = "";
        var str = occupancyObj.value.toUpperCase();
        var selectedBand = "";
        $.ajax({
            url: '<%=Url.Content("~/Fire/FindOccupancyType")%>', type: "POST", dataType: "json",
            cache: false,
            data: { term: str, matchType: "PARTIAL" },
            success: function (data) {
                response($.map(data, function (item) {
                    return { value: item }
                }))
            }
        });

    }

})
</script>

Entitiy Class:

public class FireQuote    
{        
    public FireQuote()        
    {                    
    this.BlockLevelAddOnCover = new List<BlockLevelAddOnCover>();    
    public string TFloaterPremiumPDF { get; set; }    
    public bool IsEmail { get; set; }         
    public Agent AgentDetails { get; set; }
    public string SILimit { get; set; }        
    private string _DeviationRole; 
}
public class BlockLevelAddOnCover   
{ 
    public int BlockLocationNo { get; set; }    
    public int BlockCoverId { get; set; }       
    public string BlockCoverDesc { get; set; }  
}    
}

Please Help

You are viewing reply posted by: pandeyism 11 days ago.