Ajax url does not change in asp.net mvc

2019-08-04 07:58发布

I have been trying to use ajax post to another actionresult.

However i have 3 problems about ajax.

1-Url does not change on browser.
2-I can not click to previous page and forward page on browser
3-Do i have to refresh html like  $("#BodyPage").html(mydata);?

My codes below,

Index ActionResult (Project starts from Index)

  public ActionResult Index()
    {
        return View();
    }

Index View

<body id="BodyPage">

<input type="text" id="LoginEmailText"/>
<input type="text" id="LoginPasswordText"/>

</body>

JS Code:

<script>
    function LoginButton1OnClick() {
        $.ajax({
            type: "POST",
            url: "Login/MainPageRegister",
            cache:false,
            data:
                {
                    LoginEmailText: $("#LoginEmailText").val(),
                    LoginPasswordText: $("#LoginPasswordText").val(),
                },
            success: function (mydata) {
                $("#BodyPage").html(mydata);
            }
        });
    }
</script>

MainPageRegister ActionResult:

    [HttpPost]
    public ActionResult MainPageRegister(MyModel model)
    {
        return View();
    }

MainPageRegister View:

<h1>Just for an example</h1>

My questions,

1-Why url does not change when i post data ?

2-Why i can not go previous and forwards page ?

3-Do i always have to refresh like $("#BodyPage").html(mydata)? Is there another easier way ?

Any help will be appreciated.

Thanks.

0条回答
登录 后发表回答