0

I would like to add a button which enables to do an action and also refresh the current webpage. I don't understand why the following code doesn't work. In fact the action is performed but not the refresh.

<form class="form-search" action="@Url.RouteUrl("xx")" method="post"> <button type="submit" class="btn" onClick="window.location.reload();"></button> </form> 

Any advice?

2 Answers 2

1

That doesn't make any sense. The action is actually a request for another page. The refresh is a request for the same page. Just choose one.

Sign up to request clarification or add additional context in comments.

4 Comments

basically the button should delete a picture from the page and refresh it. The delete action is working but it's not refreshing. Is it possible to do both with just one button?
You are doing exactly this with just the submit button. "Refreshing" means sending a new http request for the same page. You are doing exactly that with "action". It's something else that goes wrong, not your "refresh". The javascript is completely unnecessary.
thanks Slytael, that's clear now. I am going to investigate in other ways
i had to add in my controller return RedirectToRoute(...), you were right!
0

If you just want to just give the user a refresh button, it's simple:

<a href="./">refresh</a> 

this is extremely simple, so it does come with its share of downsides, the main one being that you lose any URL parameters and fragments. If you don't use these, then it's just fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.