Solved

assigning url to button with javascript function

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

839 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