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

  • Home
  • SEARCH
  • 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 992527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:16:57+00:00 2026-05-16T06:16:57+00:00

I need to pass a url string from the view to the controller, a

  • 0

I need to pass a url string from the view to the controller, a url that is retrieved via jquery. I tried just using the id parameter in the default routing, but that didn’t work. It didn’t accept a url string.

Calling the Controller through jquery works fine, like this:

$('#result').load('Home/Files/' + url);

This calls the correct action method, but unless I feed a simple text string it won’t work (I tested feeding the url variable a simple string just to make sure the method was called at all).

So how can I get this url string to the controller? I am trying to think about how to do this the “MVC” way, and not break that way of thinking, so I don’t want to utilize a hidden input with runat server. Could it be done with ViewData? I couldn’t think of any way though, I only know how to set ViewData in the controller and fetch the value from the view, not the other way around…

I also tried adding a custom route (before the default route):

routes.MapRoute(
    "FileManager", // Route name
    "Home/{action}/{url}", // URL with parameters
    new { controller = "Home", action = "Files", url = "" } // Parameter defaults
);

But that didn’t work either, same problem with not getting the url to the controller. I only did it because I had seen suggestions for it for people with similar problems here, but to be honest I don’t see how this could work, because how is this any different from the default route? I have no idea why the {id} parameter only seems to accept certain strings (id format strings I suppose), but unless I could specify somehow what type the url parameter should be I don’t see how adding this route should make any difference…

If someone could enlighten me I would be very grateful!

EDIT:
When I think about it, since I’m getting the content through an ajax call with jquery, I’m not sure a ViewData type solution would work anyway, because the entire page isn’t posted, or am I wrong? Keep in mind that I’m just learning MVC and jquery at the moment, so please don’t assume I have all the basics clear to me yet :-). Basically I just want to be able to pass any type of string (and possibly other types of data that is not an id) to the controller from the view…

EDIT 2:
I tried the suggested encodeURIComponent, but that didn’t work either, unless I’m doing something wrong. Here’s my code:

The url (doesn’t matter if I try it as a relative path or an absolute one using file:///)

<li><a href="#" rel="visual studio 2010/Projects/JsTree/JsTree/">Some text</a>

The jquery:

var url;
$(document).ready(function () {
    $("a").click(function () {
        url = encodeURIComponent($(this).attr("rel"));
        $('#result').load('Home/Files/' + url);
    });
});

I’m calling an action method with a string id parameter. Note again that it works fine if I pass a simple string, and the call to the action is made. But if I use the url above, the action method is never even called… I have a breakpoint there that is never reached if there is a url in the parameter!

  • 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-05-16T06:16:58+00:00Added an answer on May 16, 2026 at 6:16 am

    It’s most likely that the URL is not being encoded properly – try using encodeURIComponent().

    Another tip is to generate the URL of the action using MVC routing itself – URL.ForAction() IIRC – That way, if you ever change your routing information, all your JQuery will continue to work

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

Sidebar

Related Questions

I need to pass an string value from UItable View Controller to Uitable view
I need to pass an extra parameter :mobilejs => true from jQuery to a
I need to pass a variable which is captured from client side via jquery
I need to pass a parameter from one method in a controller to another.
I need to pass string from url: ../page.html?code=123456 to a form (eform snippet in
I need to pass an url from asp.net load_page to flowplayer javascript function here:
I need to pass a couple bits of info through the URL just by
I need to pass argument to JNLP dynamically for which I tried using a
I need to pass a parameter from an EditText and when I click the
I am passing an encrypted URL string: Default.aspx?S3tLlnIKKzE%3d I want to pass that URL

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.