开发者

Update viewdata on button clicks

<div id="newApplication" class="invisible">
     <form id="frmnewApplication" action="">
        <fieldset>
            <ul class="formone">
                <li>
                    <label class="labelone">
                        Name:</label>
                    <%--开发者_高级运维    <input type="text" id="ApplicationName" class="inputtext validate[required]" />--%>
                    <%= Html.DropDownList("ApplicationName", ViewData["AppList"] as IEnumerable<SelectListItem>)%>
                </li>

This is my div. I am fetching the values from viewdata["AppList"]. My dropdown is fetching the values from ViewData in pageload only even though I am updating my viewdata in other controller methods it is not updating the viewdata. Plz help. This is the jquery method

function updateDropdown() {
            $("#ApplicationName").html("");
            $.ajax({

                type: "POST",
                url: "/Shielding/AjaxGetDdlList",
                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        alert("Something went wrong. Please try again;");
                    }
                    else {
                        for (group in data) {
                            var newOption = $("<option></option>").attr("value", data[group].ShieldFirewallApplicationId).html(data[group].ShieldFirewallApplicationName);
                            alert(data[group].ShieldFirewallApplicationName);
                            $("#ApplicationName").append(newOption);

                        }
                    }
                }
            });
        }

This is the controller method:

public ActionResult AjaxGetDdlList()
{
    return Json(ShieldingRep.GetAllApplications());
}


You may need to use tempdata. try to use viewmodels approach you may get help from this link


Viewdata isn't persisted between calls. The problem will be found in your controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜