将一些代码添加到现有的MVC网页。该网站的所有其他部分继续正常工作。在VS2010中运行Debug,代码正常运行。上传到IIS 7.5后,它返回以下异常。有任何想法吗?如果需要,可以提供额外的代码。
由于
Value cannot be null.
Parameter name: String
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at McCarterMobile.Controllers.CartController.RemoveContribution(FormCollection form) in V:\Google Drive\Websites\Mobile Site\McCarterMobile\Controllers\CartController.cs:line 391
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 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
这是控制器代码。
383 public ActionResult RemoveContribution(FormCollection form)
384 {
385 string sessionKey = "";
386
387 if (HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null)
388 {
389 {
390 sessionKey = FormsAuthentication.Decrypt(HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value).UserData;
391 repository.RemoveContribution(sessionKey, int.Parse(form["Ref_Num"]));
392 }
393 return RedirectToAction("Index");
394 }
395 else
396 {
397 return RedirectToAction("File Not Found", "Errors");
398 }
399 }
这是cshtml代码
@using (Html.BeginForm("RemoveContribution", "Cart"))
{
<input type="submit" data-role="button" data-inline="true" data-iconpos="notext" data-icon="delete" data-iconpos="right" />
<input type=hidden name=Ref_Num value='@c.RefNum' />
}
答案 0 :(得分:0)
如果您允许,MVC框架将为您处理类型转换:
public ActionResult RemoveContribution(int? Ref_Num = null)
{
if (Ref_Num == null)
{
// report an error or whatever
}
else
{
// do something with Ref_Num
}
}
MVC框架中有很多代码支持这些内容,因此您不必继续处理类型转换等。