0

I am developing a MVC application.

In Edit View, I want to have save/submit button and cancel button.

By default MVC given 'back to list' link.this link calls index() method.

Now, I want to call this index() method on Cancel button's Onclick event , how to do this ?

<input type="submit" value="Save" onclick="return validate();" id="btnSubmit" />  
<input type="Button" value ="Cancel" onclick="Index()"style=" font-size:"1.2em"/>

What changes I have to make in above code?

1 Answer 1

4

You could use the window.location.href to redirect to a specified url:

<input type="Button" value="Cancel" onclick="window.location.href='@Url.Action("index")'" style=" font-size:"1.2em"/>

or simply use an anchor instead of a button:

@Html.ActionLink("Cancel", "Index")
Sign up to request clarification or add additional context in comments.

1 Comment

How to call a method by button without redirecting to any view? stackoverflow.com/questions/25557278/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.