2017-03-04 11 views
0

顯示錯誤值不能爲空。使用dhtmlxGantt爲ASP.NET MVC添加甘特圖任務。 在mscorlib.dll中發生類型'System.ArgumentNullException'的異常,但未在用戶代碼中處理。 其他信息:值不能爲空顯示錯誤值不能爲空。使用dhtmlxGantt將ASP.NET MVC的甘​​特圖添加任務

LINK:dhtmlx Link for Gantt Chart

繼承人我的代碼:

public static List<GanttRequest> Parse(FormCollection form, string ganttMode) 
    { 
     // save current culture and change it to InvariantCulture for data parsing 
     var currentCulture = Thread.CurrentThread.CurrentCulture; 
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; 

     var dataActions = new List<GanttRequest>(); 
     var prefixes = form["ids"].Split(','); 

     foreach (var prefix in prefixes) 
     { 
      var request = new GanttRequest(); 

      // lambda expression for form data parsing 
      Func<string, string> parse = x => form[String.Format("{0}_{1}", prefix, x)]; 

      request.Mode = (GanttMode)Enum.Parse(typeof(GanttMode), ganttMode, true); 
      request.Action = (GanttAction)Enum.Parse(typeof(GanttAction), parse("!nativeeditor_status"), true); 
      request.SourceId = Int64.Parse(parse("id")); 

      // parse gantt task 
      if (request.Action != GanttAction.Deleted && request.Mode == GanttMode.Tasks) 
      { 
//--HERE SHOWING ERROR VALUE CANNOT BE NULL--// 
        request.UpdatedTask = new GanttTasks() 
        { 
         GanttTaskId = (request.Action == GanttAction.Updated) ? (int)request.SourceId : 0, 
         Text = parse("text"), 
         StartDate = DateTime.Parse(parse("start_date")), 
         Duration = Int32.Parse(parse("duration")), 
         Progress = Decimal.Parse(parse("progress")), 
         ParentId = (parse("parent") != "0") ? Int32.Parse(parse("parent")) : (int?)null, 
         SortOrder = (parse("order") != null) ? Int32.Parse(parse("order")) : 0, 
         Type = parse("type") 
        }; 
      } 
      // parse gantt link 
      else if (request.Action != GanttAction.Deleted && request.Mode == GanttMode.Links) 
      { 
       request.UpdatedLink = new GanttLinks() 
       { 
        GanttLinkId = (request.Action == GanttAction.Updated) ? (int)request.SourceId : 0, 
        SourceTaskId = Int32.Parse(parse("source")), 
        TargetTaskId = Int32.Parse(parse("target")), 
        Type = parse("type") 
       }; 
      } 

      dataActions.Add(request); 
     } 

     // return current culture back 
     Thread.CurrentThread.CurrentCulture = currentCulture; 

     return dataActions; 
    } 
} 

我提到以上鍊接提供的,做的陳述。但在添加值時,其顯示值不能爲空。

回答

0

嘗試使用在客戶端設置task.progress默認值,

JS:

gantt.attachEvent("onTaskCreated", function(task){ 
    task.progress = 0; 
    return true; 
}); 

客戶端不設置一個新創建的任務的進度屬性的默認值,所以當您在後端進度值上插入任務的值爲空。 而且,由於後端代碼不驗證的值,大概在這條線的錯誤大火:

Progress = Decimal.Parse(parse("progress")), 

在客戶端設置的默認值,如上圖所示,或檢查空服務器上應該可以解決這個問題