【发布时间】:2013-03-15 04:10:55
【问题描述】:
我有一个从 getJSON 方法调用的 http 控制器。它的工作非常好。但现在我想在控制器方法的处理程序中执行相同的操作。我通过 getJSON 向处理程序发送一个值,它使用该值执行。
这是我的 getJSON
$(document).ready(function () {
$.getJSON('ProfileHandler.ashx', { 'ProfileName': 'Profile 1' }, function (data) {
$.each(data, function (k, v) {
alert(v.Attribute+' : '+v.Value);
});
});
});
这是我的处理程序
public void ProcessRequest(HttpContext context)
{
try
{
string strURL = HttpContext.Current.Request.Url.Host.ToLower();
//string ProfileName = context.Request.QueryString["profilename"];
string strProfileName = context.Request["ProfileName"];
GetProfileDataService GetProfileDataService = new BokingEngine.MasterDataService.GetProfileDataService();
IEnumerable<ProfileData> ProfileDetails = GetProfileDataService.GetList(new ProfileSearchCriteria { Name = strProfileName });
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
string strSerProfileDetails = javaScriptSerializer.Serialize(ProfileDetails);
context.Response.ContentType = "text/json";
context.Response.Write(strSerProfileDetails);
}
catch
{
}
}
如何调用“ProfileName”并将其传递给控制器方法?
【问题讨论】:
-
你不会
POST和GET数据,但无论如何这些参数通常在请求对象中 -
是的,仅限请求。它工作正常。我的问题不是那个
标签: javascript jquery asp.net-mvc getjson