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!