當我通過單擊提交按鈕發佈我的AJAX表單時,出現500錯誤。該處理AJAX後控制器獲取數據正常,但當我返回局部視圖,通過這條線,我得到了500:DropDownListFor()和500錯誤
return PartialView("_SiteSurveyNewClubTeam", model);
我返回部分回,而不是HTTP狀態的原因代碼是因爲如果我不這樣做,我的一個動態下拉菜單回來了。也許我正在把自己鎖在一個角落裏,在這裏。
在違規DropDownListFor()我相信提供的數據類型是否正確,並以正確的順序:(string, IList<SelectListItem>)
錯誤
The ViewData item that has the key 'DistrictSelected' is of type 'System.String'
but must be of type 'IEnumerable<SelectListItem>'.
視圖模型聲明
public IList<SelectListItem> DistrictSelect { get; set; }
public string DistrictSelected { get; set; }
來源o F中的錯誤是這條線在我看來
<span class="formColumn2">@Html.DropDownListFor(model => model.DistrictSelected, Model.DistrictSelect)</span>
不知道爲什麼我收到此。有任何想法嗎?
感謝
這裏是處理AJAX表單提交
[HttpPost]
public ActionResult ProcessFormANewClubTeam(FormANewClubTeamViewModel model)
{
var httpStatus = HttpStatusCode.BadRequest;
var cosponsors = new List<NewClubSponsor>();
var errorMessages = new StringBuilder();
var tasks = new NewClubBuilderTasks();
var clubKeyNumber = tasks.GetClubKeyNumber();
var masterCustomerId = tasks.GetMasterCustomerId();
bool exceptionRaised = false;
if (ModelState.IsValid)
{
if (model.NewClub_Id > 0)
{
//Load the entity to be partially-updated
NewClub newClub = db.NewClubs.Single(nc => nc.Id == model.NewClub_Id);
//Set the values for the fields to be updated
newClub.District = model.DistrictSelected;
newClub.Division = model.DivisionSelected;
newClub.Region = Utility.Personify.GetRegionFromDistrict(newClub.District);
newClub.ClubCounselorMasterCustomerId = model.ClubCounselorMasterCustomerId;
newClub.ClubCounselorContact = model.ClubCounselorContact;
newClub.ClubCounselorEmail = model.ClubCounselorEmail;
newClub.ClubCounselorPhone = model.ClubCounselorPhone;
newClub.DateUpdated = DateTime.Now;
try
{
//Execute the UPDATE
var dbResult = db.SaveChanges() > 0;
httpStatus = HttpStatusCode.OK;
}
catch (SqlException ex)
{
//Catch exceptions here
}
// return new HttpStatusCodeResult((int) httpStatus);
return PartialView("_SiteSurveyNewClubTeam", model);
} else {
var errors = ModelState
.Where(x => x.Value.Errors.Count > 0)
.Select(x => new {x.Key, x.Value.Errors})
.ToArray();
return new HttpStatusCodeResult((int) httpStatus);
}
}
你可以發佈ajax嗎? – ganders
是的,AJAX表格確實發佈的很好 – Slinky
對不起,我的意思是粘貼ajax代碼在這裏... – ganders