我正在做asp.net MVC我想显示我的索引,但是我在调用方法时遇到了问题。
有人能说出我做错了什么吗?
这是我的索引控制器:
public ActionResult Index(int pageNumber, int pageSize, string filter, string sortColumn, string sortOrder, out int totalCount)
{
List<UserActivityModels> userActivity = null;
totalCount = 0;
string sqlWhere = string.Empty;
sqlWhere = string.IsNullOrEmpty(filter) ? sqlWhere :
sqlWhere + "AND (ContactId LIKE @filter)";
string sqlOrderBy = "ORDER BY" + sortColumn + "" + sortOrder;
String sqlSelect = @"
SELECT Id
,CreatedBy
,CreatedOn
,ModifiedBy
,ModifiedOn
,ContactId
,EntityName
,EntityId
,ActivityType
,ActivityStatus
,DueDate
,ActualEndDate
,MasqueradeOn
,MasqueradeBy
FROM UserActivity
#WHERE
#ORDERBY
LIMIT @PageSize OFFSET @PageNumber
";
string sqlCount = @"
SELECT COUNT(Id) TotalCount
FROM UserActivity
#WHERE
";
sqlCount = sqlCount.Replace("#WHERE", sqlWhere);
sqlSelect = sqlSelect.Replace("#WHERE", sqlWhere);
sqlSelect = sqlSelect.Replace("#ORDERBY", sqlOrderBy);
try
{
using (IDbConnection db = new MySqlConnection(ConfigurationManager.ConnectionStrings["CRMPORTALSQLCONN"].ConnectionString))
{
userActivity = (List<UserActivityModels>)db.Query<UserActivityModels>(sqlSelect, new
{
@filter = "%" + filter + "%",
@PageSize = pageSize,
@PageNumber = (pageNumber - 1) * pageSize
});
totalCount = (int)db.ExecuteScalar<int>(sqlCount, new
{
@filter = filter
});
}
}
catch (Exception ex)
{
throw new Exception("Unable to retrieve data from DB.", ex);
}
return View(userActivity);
}
//POST: /UserActivity/Index
[HttpPost]
public ActionResult Index(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
错误说:
无法调用action方法&System; Web.Mvc.ActionResult索引(Int32,Int32,System.String,System.String,System.String,Int32 ByRef)&#39;在控制器&#39; iCarAsia.SellerPortal.App.CRMPortal.Controllers.UserActivityController&#39;因为参数&#39; Int32&amp; TOTALCOUNT&#39;通过引用传递。
参数名称:methodInfo
由于
答案 0 :(得分:1)
此参数out int totalCount
会导致您的错误。您通过互联网发送数据,不能通过引用传递参数。我很惊讶甚至编译。如果要返回总计数,请使用
public ActionResult Index(int pageNumber, int pageSize, string filter, string sortColumn,
string sortOrder)
{
int totalCount = ...
return Json(totalCount);
}
这会将您的数据序列化为Json,并返回JsonResult
,该ActionResult
继承自1/2/2015 6:00:00 AM
1/2/2015 6:00:03 AM
1/2/2015 6:00:06 AM
1/2/2015 6:00:09 AM
。