-1

控制器代码:

private UBADBEntities db = new UBADBEntities();

    public ActionResult Index()
    {
        ViewBag.Pos1 = new SelectList(db.Positions, "posID", "posName");
        ViewBag.Pos2 = new SelectList(db.Positions, "posID", "posName");
        var applications = db.Applications.Include("Position").Include("Position1");
        return View(applications);
    }

    [HttpPost]
    public ActionResult Index(int id, int listPos1, int listPos2)
    {
        var applicationQuery =
            from app in db.Applications
            where app.CandidateID == id
            select app;

        ViewBag.Pos1 = new SelectList(db.Positions, "posID", "posName", listPos1);
        ViewBag.Pos2 = new SelectList(db.Positions, "posID", "posName", listPos2);

        foreach (var application in applicationQuery)
        {
            if (application.CandidateID == id)
            {
                application.Pos1 = listPos1;
                application.Pos2 = listPos2;
            }
        }

        db.SaveChanges();
        return View(db.Applications.ToList());
    }

查看代码:

<div id="firstPos-@item.CandidateID.ToString()" class="show">@Html.DisplayFor(modelItem => item.Position.posName)</div>
<div id="listPos1-@item.CandidateID.ToString()" class="invisible">@Html.DropDownList("Pos1", String.Empty)</div>
@Html.DisplayFor(modelItem => item.Position1.posName)
<div id="listPos2-@item.CandidateID.ToString()" class="invisible">@Html.DropDownList("Pos2", String.Empty)</div>

JS脚本:

function ShowEdit(par) {
        $("#listPos1-" + par).attr("class", "show");
        $("#secondPos-" + par).attr("class", "invisible");
        $("#listPos2-" + par).attr("class", "show");
        $("#btnEdit-" + par).attr("class", "btn-toolbar text-center btn-group btn hide");
        $("#btnSave-" + par).attr("class", "btn-toolbar text-center btn-group btn show");
    }
    function SaveEdit(par) {
        $("#listPos1-" + par).attr("class", "invisible");
        $("#secondPos-" + par).attr("class", "show");
        $("#listPos2-" + par).attr("class", "invisible");
        $("#btnEdit-" + par).attr("class", "btn-toolbar text-center btn-group btn show");
        $("#btnSave-" + par).attr("class", "btn-toolbar text-center btn-group btn hide");

        var _listPos1 = $("#listPos1-" + par).val();
        var _listPos2 = $("#listPos2-" + par).val();
        var url = '@Url.Action("Index","Application")';
        $.post(url, { id: par listPos1: _listPos1, listPos2: _listPos2 }, function (data) {
            $("#divResult").html(data);
        });
    }
4

2 回答 2

0

尝试使用以下代码,这可能会对您有所帮助。

$('#<%=yourID.ClientID %> option:selected').val()
于 2013-06-14T05:27:28.487 回答
0

检查您的帖子语法。缺少一个逗号

$.post(url, { id: par , listPos1: _listPos1, listPos2: _listPos2 }, function (data) {
        $("#divResult").html(data);
});
于 2013-06-14T05:32:08.973 回答