0

我有一个大问题..请帮助我。当它的值改变时我有下拉列表我想填充一些文本框。我写一个动作并返回带有新值的视图。但是我的页面不刷新..这是我的代码请帮我

       public ActionResult Create()
    {

        var varizeMoredi = new VarizeMorediModel();

        var settleTitles = db.SettleTitles.ToList();
        settleTitles.Insert(0, new SettleTitle() { ID = 0, Title = string.Empty });
        varizeMoredi.SettleTitles = new SelectList(settleTitles, "ID", "Title");

        return View("Create", varizeMoredi);
    }


    public ActionResult GetSettleTitleInfo(string customer, int settleTitleId)
    {
       // ModelState.Remove("BankAccountName");
        var varizeMorediModel = new VarizeMorediModel();
        var settleTitle = db.SettleTitles.Where(a => a.ID == settleTitleId).SingleOrDefault();
        varizeMorediModel.SettleTitle = settleTitle;
        varizeMorediModel.Price = settleTitle.Price.ToString("N0");
        varizeMorediModel.BankAccountName = settleTitle.BankAccount.Title;
        var settleTitles = db.SettleTitles.ToList();
        settleTitles.Insert(0, new SettleTitle() { ID = 0, Title = string.Empty });
        varizeMorediModel.SettleTitles = new SelectList(settleTitles, "ID", "Title", settleTitleId);

          return View("Create", varizeMorediModel);
        // return RedirectToAction("Create", varizeMorediModel);
        // return Json(new { result = varizeMorediModel });
        // var categoris = db.Categories.Where(m => m.Type1.Id == id).Select(c => new { c.Id, c.Title });
        // return Json(settleTitle, JsonRequestBehavior.AllowGet);


    }`<script type="text/javascript">
$(function () {



    $("select#SettleTitleId").change(function (evt) {

      @*  var urlact = '@Url.Action("GetSettleTitleInfo")';
        var model = '@Html.Raw(Json.Encode(Model))';*@
        //alert(model);
        // alert(JSON.stringify(model));
        if ($("select#SettleTitleId").val() != "0") {

            var userElement = $('#@(Html.IdFor(m => m.Customer))');

            $.ajax({
                url: '@Url.Action( "GetSettleTitleInfo", "VarizeMoredi")',
                type: 'POST',
                //  datatype: "json",

                // contentType: "application/json; charset=utf-8",

                data: {

                    customer: userElement.val(),
                    settleTitleId: $("select#SettleTitleId").val()//,

                },
                //success: function (data) {
                //    alert(data);

                //},







                error: function (xhr) {
                    alert("Something went wrong, please try again");
                }
            });
        }
    });
});

`

4

1 回答 1

0

你为什么要注释掉脚本部分的成功属性,它实际上是负责视图更改的。

于 2013-06-07T08:30:18.020 回答