Solved

assigning url to button with javascript function

Posted on 2015-02-23
1
105 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now