0
Ajax调用在我的控制器之间得到复位,返回查看该方法还初始化一些值,一些类级别的属性:价值控制器
private string igc = String.Empty;
private string igcCode = String.Empty;
private bool isSuggested = false;
public ActionResult Codes(Codes objCodes)
{
try
{
FillDropDowns(objCodes);
igc = String.Empty;
if (objICDCodes.FromWhere.IndexOf("MedicalInfo-Suggested") >= 0)
{
igc = objCodes.FromWhere.Remove(0, "MedicalInfo-Suggested-".Length);
igcCode = igc.Substring(0, igc.IndexOf("-")).Trim();
objCodes.ICGCode = igcCode;
isSuggested = true;
}
}
catch (Exception ex)
{
//logging error
ElmahLogUtility.ErrorException(ex);
}
return View(base.GetViewPath("Codes"), objCodes);
}
此外,有这种方法,它被调用到数据绑定到页面上的网格:
public JsonResult GetSelectedCodesInfo(List<SearchField> searchFields, GridDataSourceRequest request)
{
//creating the instance of DataSourceResult.
DataSourceResult dataSourceResult = null;
try
{
// Creating the instance of CommonBLL to load the values.
CommonBLL objCommonBLL = new CommonBLL();
if (isSuggested)
{
searchFields.Add(new SearchField() { ElementName = "aIGCode", Value = igcCode });
searchFields.Add(new SearchField() { ElementName = "aFor", Value = "EtiologicDiagnosis" });
}
// Getting the Codes information and storing in the DataSource Result.
dataSourceResult = objCommonBLL.GetSelectedCodesInfo(searchFields, request);
}
catch (Exception ex)
{
//Logging the Exception
ElmahLogUtility.ErrorException(ex);
}
// Returning the Result.
return Json(dataSourceResult, JsonRequestBehavior.AllowGet);
}
isSuggested
被设置为当创建视图true
,但是当数据被绑定到网格isSuggested
设置为false
出于某种原因。
我的网格是在剃刀视图中定义像这样:
@Html.Grid("CodesSelectionGrid").ReadSource("Controller", "GetSelectedCodesInfo").OnGridDataBound("AssignCodeValues").Lazyload(true).EnableGrouping(false).EnableSorting(true).PageSize(10).Height("390px").Width("610px").EnablePaging(true).EnableFiltering(false).EnableMultiSelect(true).SelectionMode(SelectionMode.Single, "GetSelectedCodeDetails").RowSelection(GridRowSelection.None).ShowToolBar(true).SelectionCSSClass("icd-editable-cell").PageButtonCount(3)
即.ReadSource("Controller", "GetSelectedCodesInfo")
位是什么是指控制器和控制器上的方法调用。所以,它调用了上面的第二个代码片段。
我必须访问我的Controller
类的两个单独的实例,但我不知道如何解决此问题。我怎样才能做到这一点?我怎么能让我的网格通过Codes
对象的引用?然后,我可以从那里获取网格值...
谢谢;我怀疑这是由设计。我只是不知道如何处理它。我可能会按照你的建议把它放到会话变量中。如果有效,我会接受你的回答。 – sab669
那么,你的解决方案解决了我的问题......但不幸的是它自身存在问题。虽然谢谢! – sab669
4.通过HTTP Post的隐藏字段来回传递,类似于ViewState在asp.net中的工作方式。 –