问题描述
我有保存编辑的字段在我的MVC项目的问题。当我点击提交按钮,我得到一个错误
I am having an issue with saving the edited fields in my MVC project. When I click the submit button I get an error
值不能为空。
参数名:项目
说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。
Value cannot be null.Parameter name: items Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
异常详细信息:System.ArgumentNullException:值不能为空。
参数名称:项目
Exception Details: System.ArgumentNullException: Value cannot be null.Parameter name: items
源错误:
63号线:
64号线:
65号线:@ Html.DropDownListFor(型号=> model.EventTypeID,新的SelectList(ViewBag.EventTypes,EventTypeID,EventType1),选择)
66号线:
第67行:
Line 63:Line 64:Line 65: @Html.DropDownListFor(model => model.EventTypeID, new SelectList(ViewBag.EventTypes, "EventTypeID", "EventType1"), "Choose")Line 66:Line 67:
我尝试过的一些事情,我已经看到了互联网上,但它似乎并没有为我做任何事情:(帮助将AP preciated谢谢!
I have tried some things that I have seen on the internet but it doesn't seem to be doing anything for me :( Help would be appreciated thank you!
这是我的控制器当我把一个破发点这里从来没有触发。
this is my controller When I put a break point here it never triggers.
[HttpPost]
public ActionResult IndexPST(Event_Setup es)
{
db.Event_Setup.Add(es);
db.SaveChanges();
return View("Index",es);
}
这是我的看法。
@model DixonGroupInc.Models.Event_Setup
<link href="~/Content/EventManagement.css" rel="stylesheet" />
@using (Html.BeginForm("IndexPST", "EventManagement", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div id="cntr">
<div id="emLoc">
<table id="ldTbl">
<thead>
<tr>
<th class="ln">
<img src="~/Images/4.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
<th>
<img src="~/Images/5.gif" />
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="chosen space">EventMetadata
</td>
<td class="space">Client / Vendor
</td>
<td class="space">Venu info
</td>
<td class="space">Sponsored Participants
</td>
<td class="space">Event Services
</td>
</tr>
</tbody>
</table>
</div>
<div id="emSetup">
Setup Meeting
</div>
<div id="emTable">
<table class="myTbl">
<tr>
<td class="lblEvent clm1">
@Html.Label("Event Type")
</td>
<td class="clm2">
@Html.DropDownListFor(model => model.EventTypeID, new SelectList(ViewBag.EventTypes, "EventTypeID", "EventType1"), "Choose")
</td>
<td class="clm3">
@{Html.RenderAction("EventType", "EventManagement");}
</td>
</tr>
<tr class="rows">
<td class="lblEvent clm1">
@Html.Label("Event Title")
</td>
<td class="clm2">
@Html.EditorFor(model => model.EventTitle)
@Html.ValidationMessageFor(model => model.EventTitle)
</td>
</tr>
<tr>
<td class="lblEvent clm1">
@Html.Label("Event Identifier")
</td>
<td class="clm2">
@Html.EditorFor(model => model.EventIdentifier)
@Html.ValidationMessageFor(model => model.EventIdentifier)
</td>
</tr>
</table>
<table class="dateTbl">
<tr class="rows">
<td class="lblEvent clm1">
@Html.Label("Event Date From")
</td>
<td class="clm2">
@Html.TextBoxFor(model => model.EventDateFrom, new { @class = "dateFrom" })
@Html.ValidationMessageFor(model => model.EventDateFrom)
</td>
<td class="lblEvent">
@Html.Label("To")
</td>
<td class="clm4">
@Html.TextBoxFor(model => model.EventDateTo, new { @class = "dateTo" })
@Html.ValidationMessageFor(model => model.EventDateTo)
</td>
</tr>
</table>
<table class="myTbl">
<tr>
<td class="lblEvent clm1">
@Html.Label("Event Description")
</td>
<td class="clm2">
@Html.TextAreaFor(model => model.EventDescription, new
{
id = "taED"
})
<div>
<span id="charLeft2"></span>characters remaining.
</div>
@Html.ValidationMessageFor(model => model.EventDescription)
</td>
</tr>
<tr class="rows">
<td class="lblEvent clm1">
@Html.Label("Custom Message")
</td>
<td class="clm2">
@Html.TextAreaFor(model => model.CustomMessage, new
{
id = "taCM"
})
<div>
<span id="charLeft1"></span>characters remaining.
</div>
@Html.ValidationMessageFor(model => model.CustomMessage)
</td>
</tr>
<tr>
<td class="lblEvent clm1">
@Html.Label("Instructions")
</td>
<td class="clm2">
@Html.TextAreaFor(model => model.Instructions, new
{
id = "taInstrct"
})
<div>
<span id="charLeft"></span>characters remaining.
</div>
@Html.ValidationMessageFor(model => model.Instructions)
</td>
</tr>
</table>
<table class="myTbl">
<tr class="rows">
<td>
@{Html.RenderAction("AddTrack", "EventManagement");}
</td>
</tr>
<tr>
<td>
@{Html.RenderAction("EventTrack", "EventManagement");}
</td>
</tr>
</table>
<table class="myTbl">
<tr class="rows">
<td class="lblEvent clm1">
@Html.Label("CFP Pocess")
</td>
<td class="clm2">
@Html.RadioButtonFor(model => model.CFPRequired, "true") Yes
</td>
<td class="clm3">
@Html.RadioButtonFor(model => model.CFPRequired, "false") No
</td>
</tr>
</table>
</div>
<div id="emSubmit">
<input type="submit" value="Save & Next" id="submit" />
</div>
</div>
}
推荐答案
Viewbag可能不可靠所以一般不建议通过您的下拉通过viewbag列表数据。我建议将其添加到您的视图模型来代替。在你Event_Setup类请确保您有
Viewbag can be unreliable so generally it isn't recommended to pass your drop down list data through the viewbag. I would recommend adding it to your view model instead. In your Event_Setup class make sure that you have
public int EventTypeID { get; set; }
和
public List<SelectListItem> EventTypeList { get; set; }
您的控制器上让你可以设置EventTypeID设置的下拉默认下来,你的控制器应该有类似
on your controller get you can set EventTypeID to set a default on the drop down so your controller should have something like
Event_Setup es = new Event_Setup();
es.EventTypeID = //default value if you want;
es.EventTypeList = //Method call here where List<SelectListItem> is returned with your event list
然后在您的视图中,可以改变你的下拉菜单
then on your view you can change your drop down to
@Html.DropDownListFor(x => x.EventTypeID, Model.EventTypeList)
这篇关于发行保存编辑后的数据:DDL值不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!