title: System.InvalidOperationException: Nullable object must have a value.ASP.NET MVC
body: <p>I am tired of fixing this error but nothing is working.</p>
  
  <p><strong>Here is the error:</strong></p>
  
  <blockquote>
    <p>System.InvalidOperationException: Nullable object must have a value.<br>
    at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource
    resource)    at System.Nullable<code>1.get_Value()    at
    Finance.Calculator.Presentation.Admin.Areas.HDGS.Controllers.TransactionController.Edit(Int64
    TransactionId, String returnURL) in
    d:\BuildAgent2\work\83d988abf03ace44\Code\Presentation\Finance.Calculator.Presentation.Admin\Areas\HDGS\Controllers\TransactionController.cs:line
    44    at lambda_method(Closure , ControllerBase , Object[] )    at
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
    controller, Object[] parameters)    at
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
    controllerContext, IDictionary</code>2 parameters)    at
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
    controllerContext, ActionDescriptor actionDescriptor, IDictionary<code>2
    parameters)    at
    System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12()
    at
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
    filter, ActionExecutingContext preContext, Func</code>1 continuation)    at
    System.Web.Mvc.ControllerActionInvoker.&lt;>c__DisplayClass15.&lt;>c__DisplayClass17.b__14()
    at
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
    controllerContext, IList<code>1 filters, ActionDescriptor actionDescriptor,
    IDictionary</code>2 parameters)    at
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
    controllerContext, String actionName)</p>
  </blockquote>
  
  <p><strong>Here is my Code:</strong></p>
  
  <pre><code>public ViewResult Edit(string TId, string returnURL)
      {
          long tid = !string.IsNullOrEmpty(TId) ? Convert.ToInt64(TId) : Convert.ToInt64(Request.QueryString["TId"].ToString());
          var TransactionItem = db.HDGSAccTransaction.SingleOrDefault(t =&gt; t.TransactionID.Equals(tid));
          TransactionVM oTrns = null;
          if (!string.IsNullOrEmpty(returnURL))
          {
              TempData["ReturnUrl"] = returnURL;
          }
          if (TransactionItem != null)
          {
              oTrns = new TransactionVM
              {
                  TRef = TransactionItem.dimTransaction.TRef,
                  Yr = TransactionItem.Yr,
                  IcV = (decimal)TransactionItem.IcV,
                  OFv = (decimal)TransactionItem.OFv,
                  OCBv = (decimal)TransactionItem.OCBv,
                  OOBv = (decimal)TransactionItem.OOBv,
                  OInv = (decimal)TransactionItem.OInv
              };
          }
  
          return View(oTrns);
      }
  </code></pre>
  
  <p><strong>Please Note: This code runs fine in the development environment from Visual Studio but not on the servers when it is deployed.</strong></p>