Solved

assigning url to button with javascript function

Posted on 2015-02-23
1
107 Views
Last Modified: 2015-02-23
I'm using Asp.NET MVC 5.

So i have two pages in my application.

On launch Index.cstml is the view that is displayed.
On this Index i have a link that takes me to my other page called TestPage.cshtml.

Both of these views are in the same Home folder. This Home folder is inside the Views folder of the mvc application.


Example 1:

Right now on my TestPage.csthml I have a regular text link that looks like this.

@Html.ActionLink("Go Back To Index Page", "Index", new { Rno = Model.RegionNo })

Open in new window


If you click on it it takes you back to the Index page.

I want to replace this text link with a Button.

Example 2: I replaced the actionlink shown above with a button like this. It seems to work fine:

<input type="submit" value="GoBack" class="GoBackToIndexButton" onclick="javascript: history.back()" />

Open in new window


Example 3:

I also tried a link like this and styled a table to look like  a button and this works fine.

                <a href="~/Home/Index/@RegionNo/">
                    <table id="BackToIndexBtn">
                        <tr>
                            <td style="width: 100%;" class="GoBackToIndexButtonStyle">Cancel</td>
                        </tr>
                    </table>
                </a>

Open in new window



Is there a way to set a url that looks like this <a href="~/Home/Index/@RegionNo/"></a> to a input button?

So in a button like this instead of using go the javascript back funtion I want to have the button use this url.

<input type="submit" value="GoBack" class="GoBackToIndexButton" onclick="javascript: history.back()" />
0
Comment
Question by:maqskywalker
1 Comment
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 500 total points
ID: 40626587
Not sure why you have a submit button for Go Back functionality. If you need to do a POST you may need a submit, otherwise a button would be enough right?
<input type="button" value="GoBack" 
onclick="location.href='@Url.Action("Index", "Home", new { id = @Model.FirstorDefault.RegionNo.ToString()}, null)'" />

Open in new window


Please let know if any issues. HTH.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question