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中的工作方式。 –