简体   繁体   中英

asp.net MVC partial view

I have created a function for load event like this:

$(function() {
  $('#dvGames').load(
     '<%= Url.Action("Partial3", "LiveGame") %>',{ gameDate: '2011-03-06' }
  );
});

and it works. Also, I have created a function for date change like this:

$(function() {
  $('#datepicker').datepicker({
    onSelect: function(dateText, inst) {

        $.ajax({

            type: "POST",

            url: "/LiveGame/Partial3",             

            data: "gameDate=" + dateText,

            success: function(result) {

                alert(result);

                var domElement = $(result); // create element from html

                $("#dvGames").append(domElement); // append to end of list        

            }

        });

    }

  });
});

but it doesnt work. neither it goes in controller action. My controller action is:

 public ActionResult Partial3(string gameDate)
    {

        return PartialView("Partial3");

    }

Please suggest me solution to this.

2 options will work for this

url: "/LiveGame/Partial3?gameDate=" + dateText

or

data: { gameDate : dateText }

don't use both and the 2nd is probably best practice use of JSON.

I don't like query strings in MVC post callbacks as they will persist across posts even if you don't want them to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM