Я получаю эту очень раздражающую ошибку, когда удаленная проверка пытается проверить, существует ли уже значение в БД:
Словарь параметров содержит пустую запись для параметра 'gbsNumber', не допускающего нулявведите «System.Int32» для метода «System.Web.Mvc.JsonResult DoesGbSNumberExist (Int32)» в «ADVWKSP.Controllers.CRMTItemsController».Необязательный параметр должен быть ссылочным типом, обнуляемым типом или быть объявлен как необязательный параметр.Имя параметра: параметры
at System.Web.Mvc.ActionDescriptor.ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary`2 parameters, MethodInfo methodInfo)
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.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
Это происходит с перебоями, и я не могу выработать какой-либо паттерн - он кажется абсолютно случайным.
Это происходит на 2 моихполя, оба из которых соответствуют целочисленным свойствам в модели представления.
Мало того, что он заполняет мой журнал ошибок, но он разбивает форму так, что иногда кнопка отправки не работает, что являетсятак раздражает.
Контроллер
[HttpPost]
public JsonResult DoesGbSNumberExist(int gbsNumber)
{
using (var db = new ADVWKSPEntities())
{
return Json(!db.CRMTItems.Any(i => i.GbsNumber == gbsNumber));
}
}
ViewModel
public class CRMTItemViewModel
{
public int Id { get; set; }
[Required]
[Display(Name = "Project Title")]
[Remote("DoesProjectTitleExist", "CRMTItems", HttpMethod = "POST",
ErrorMessage = "Workspace for that project title already exists.")]
public string ProjectTitle { get; set; }
[Required]
[Display(Name = "Project Stage")]
public ProjectStage? ProjectStage { get; set; }
[Required]
[Display(Name = "CRMT Number")]
[Remote("DoesCrmtNumberExist", "CRMTItems", HttpMethod = "POST",
ErrorMessage = "Workspace for that CRMT number already exists.")]
public int? CRMTNumber { get; set; }
[Required]
[Display(Name = "GBS Number")]
[Remote("DoesGbSNumberExist", "CRMTItems", HttpMethod = "POST",
ErrorMessage = "Workspace for that GBS project number already exists.")]
public int? GbSNumber { get; set; }
public bool Confidential { get; set; }
[Required]
[Display(Name = "Project Managers")]
public IEnumerable<string> SelectedTags { get; set; }
}
Просмотр
@using (Ajax.BeginForm("Create", "CRMTItems", new AjaxOptions
{
HttpMethod = "Post",
UpdateTargetId = "divToUpdate",
OnBegin = "submitBegin",
OnSuccess = "submitSuccess",
OnFailure = "submitFailure",
OnComplete = "submitComplete"
}, new { @ID = "AjaxForm" }))
{
<div class="form-horizontal">
<h4>New Project Workspace Form</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.ProjectTitle, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProjectTitle, new { htmlAttributes = new { @class = "form-control"} })
@Html.ValidationMessageFor(model => model.ProjectTitle, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProjectStage, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(model => model.ProjectStage, new { @class = "form-control"})
@Html.ValidationMessageFor(model => model.ProjectStage, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CRMTNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CRMTNumber, new { htmlAttributes = new { @class = "form-control"} })
@Html.ValidationMessageFor(model => model.CRMTNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.GbSNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.GbSNumber, new { htmlAttributes = new { @class = "form-control"} })
@Html.ValidationMessageFor(model => model.GbSNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Confidential, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.CheckBoxFor(model => model.Confidential, new { @class = "form-control", @style = "height:17px;" })
@Html.ValidationMessageFor(model => model.Confidential, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => Model.SelectedTags, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.HiddenFor(m => m.Id)
@Html.ListBoxFor(m => m.SelectedTags, new SelectList(users, "UserName", "DisplayName"), new { @class = "teamSelecter", name = "states[]", multiple = "multiple", style = "display:none; width:100%;"})
@Html.ValidationMessageFor(model => model.SelectedTags, "", new { @class = "text-danger" })
<p id="pmWarning" class="text-danger" hidden>Please select one or more project managers</p>
</div>
</div>
<br />
<button id="formSubmit" class="btn btn-default btn-lg pull-right" type="submit" value="submit">Submit</button>
<div class="loader pull-right" hidden></div>
</div>
}