Solved

assigning url to button with javascript function

Posted on 2015-02-23
1
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

749 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