Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:30:24+00:00 2026-06-17T12:30:24+00:00

I am trying to pass a string value to a create item dialog, and

  • 0

I am trying to pass a string value to a create item dialog, and am not sure on how to do it.

This is the code in my view:

JavaScript:

function newRoute() {
    $.ajax({
        url: '@Url.Action("Create")',
        success: function (data) {
            if (data == "success") //successfully created the new route
                window.location.href = '@Url.RouteUrl(ViewContext.RouteData.Values)'
            else
                $.facybox(data); // there are validation errors, show the dialog w/ the errors
        }
    });
}

View:

<td>@route</td>
<td>
    <a href="javascript:newRoute();" class="button">Add</a>
</td>

Controller:

public ActionResult Create(string routeName = "")
    {
        PopulateRouteInfoViewBag();

        var newRoute = new RouteInformation();

        newRoute.Name = routeName;

        return View(newRoute);
    }

I’m trying to take the value in @route and pass it over to the Create controller to have my dialog pop up with the passed in string value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:30:25+00:00Added an answer on June 17, 2026 at 12:30 pm

    Use the ActionLink html helper method and pass the route variable like this.

    @{
       string route="somevaluehere";
     }
    @Html.ActionLink("Add","Create","YourControllerName",
                              new { routeName=route},new {@id="addLnk"})
    

    Now handle the click event

    $(function(){
    
       $("#addLnk").click(function(e){
         e.preventDefault();  //prevent normal link click behaviour
         var _this=$(this); 
    
          //do your ajax call now
          $.ajax({
            url: _this.attr("href"),
            success: function (data) {
                if (data == "success") //successfully created the new route
                    window.location.href = 'someValidUrlHere'
                else
                    $.facybox(data); 
             }
           });
    
       });     
    
    });
    

    Also, You may consider building the path to the new page(action method) and return that as part of your JSON result and let the client read it from the JSON.

    instead of appending the route variable value to the querystring, you may consider it as the part of message body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to pass a string from main to another function. this string is
I have been trying to pass a string value from one method into another.
I'm trying to pass an Int value pulled from a JSON String to reduce
Trying to pass a string argument to a function, which will then be used
I'm trying to pass a string argument to a target function in a process.
I am trying to pass a SelectListItem to a view. This checkbok list will
I'm trying to create a string to pass to a PHP file with numerous
I'm trying to convert this function into PHP but somehow it does not give
I am trying to pass an array of Student into the function processStudent(string myFilename,
I'm trying to pass a string to chdir(). But I always seem to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.