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 1100045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:49:27+00:00 2026-05-17T00:49:27+00:00

Hi guys i’m new to JSon and not too sure how do i pass

  • 0

Hi guys i’m new to JSon and not too sure how do i pass the data around. I am using ASP.NET MVC as my development platform.

In The View:

 $(document).ready(function() {
    $("select#Colors").change(function() {
       var photoCategory = $("#Colors > option:selected").attr("value"); // 1st parameter
       var userID = $(".userID").attr("value"); // 2nd parameter         
       $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "/FindPhotos/" + photoCategory ,
            data: "{}",
            dataType: "json",

            success: function(data) {
            $('#ProductsDiv > div').remove(); 
                if (data.length > 0) {
                    var options = ''; 
                } .......
       });
    });
});

In Global.asax:

routes.MapRoute(
       "FindPhotos",
       "FindPhotos/{category}",
        new { controller = "Clinical", action = "FindPhotosByCategory", category = "" }
       );

So everything works fine this way since i’m only passing one parameter, ‘photoCategory’, in the $.ajax url. My goal here now is to pass a 2nd parameter, which is the userID, so i can use them both in the controller method below.

In The Controller:

 public JsonResult FindPhotosByCategory(string category, string userID) {

        List<PhotoSet> photoset = Repository.GetPhotoSetByUserID(userID);

        return new JsonResult
        {
             Data = (from p in photoset 
                     where p.PhotoCategory == category
                     select p).ToArray<PhotoSet>()
        };
    }

Does anyone know how to write the $.ajax() method so i can pass in the 2 parameters to the controller? thanks!

  • 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-17T00:49:28+00:00Added an answer on May 17, 2026 at 12:49 am

    Depends on how you want to pass it. You’re doing a GET but your route won’t support a userId as a route parameter so you could pass it on the query string. The URL would be /FindPhotos/lolcats?UserId=123.

    That said, are you wanting to let the person pick the user or are you going to use the user id of the currently logged in user. If it’s the latter I’d argue that you just grab that from the controller and keep the route clean.

    In the spirit of keeping the route clean, I’d actually change the route to be something like the following:

    routes.MapRoute( 
           "FindPhotos", 
           "FindPhotos/{category}/{userId}", 
            new { controller = "Clinical", action = "FindPhotosByCategory", category = "", userId=UrlParameter.Optional } 
           ); 
    

    This would give you the option of making userId optional and then filtering based on whether or not it’s supplied. Your ajax call then becomes:

       $.ajax({ 
            type: "GET", 
            contentType: "application/json; charset=utf-8", 
            url: "/FindPhotos/" + photoCategory + "/" + userId , 
            data: "{}", 
            dataType: "json", 
    

    In the end, it has nothing to do with JSON and everything to do with how you invoke the URL. Again, this is GET so you can just pass it on the URL and be fine.

    On a side note — and as I’m sure you are aware — I’d try to avoid putting actual user ids into the markup or anywhere else for that matter for security purposes. If you have to do that, make sure you secure access somehow within the business logic/data access portions of your code.

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

Sidebar

Related Questions

Guys I am a new bee to asp .net mvc 3. In the MS
Guys I am new to android programming, I tried to send data to a
Guys I've a Situation here.. I've Developed a Website using C# .Net framework 4.0,
Guys, I am not exactly sure what happens here for the if statement. I
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
guys which text editor is good for Rubyonrails? i m using Windows and i
guys, I'm trying to realize viewing comments on internet portal and I'm using UITableView.
Guys I'm new to Android actually, i created an android UI with eclipse, its
Guys I've been asking around and nobody can really tell me the benefits of

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.