Solved

assigning url to button with javascript function

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now