System.InvalidOperationException: Nullable Objekt muss einen value.ASP.NET MVC

Ich bin es müde, die Festsetzung dieser Fehler, aber nichts funktioniert.

Hier ist der Fehler:

System.InvalidOperationException: Nullable Objekt muss einen Wert haben.

System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource -
resource) bei System.Nullable1.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
2-Parameter) bei
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary2
parameters) at
System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext preContext, Func
1 continuation) bei
System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.b__14()
bei
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
controllerContext, IList1 filters, ActionDescriptor actionDescriptor,
IDictionary
2-Parameter) bei
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName)

Hier ist mein 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 => 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);
    }

Bitte Beachten Sie: Dieser code läuft Prima in der Entwicklungsumgebung von Visual Studio, aber nicht auf den Servern, wenn es bereitgestellt wird.

welche Linie hat es Fehler auf? Nur nicht werfen-code bei uns, versuchen, Sachen heraus zu helfen, nutzen unsere Zeit
Was ist der Typ von TransactionItem.IcV? wenn es decimal? verwenden GetValueOrDefault anstelle von cast (gleich für alle anderen Requisiten).
Valamas - AUS: Danke. Aber dies funktioniert gut in meine dev-Maschine und nicht auf dem server. Das ist, warum ich don ' T haben irgendwelche Tipps
ich denke, dass ist der Grund, warum man es nur auf deinem server ist, dass die Variablen unterschiedliche Werte haben, da. Ich nehme an, Sie haben eine Nullable<T> die null. Dann ist die explizite Umwandlung nach dezimal wirft die Ausnahme.

InformationsquelleAutor Todd Wilson | 2014-07-03

Schreibe einen Kommentar