我试着从配置页面为用户保存一些数据 - 但是我只是“空”回来了.-任何人都有任何想法 - 我怎么能解决我的问题?
多数民众赞成我的页面:
@using (Html.BeginForm())
{
<main>
<fieldset>
<div id="edit_trsconfiguration">
<div id="edit_headbar">
<h1>Arbeitszeit - Konfiguration von:</h1>
<div id="edit_name">
<p>@(Model.Name)</p>
</div>
<div id="edit_headbar_positioning">
<div id="edit_replacement">
<p>Standardvertretung</p>
@(Html.Kendo().DropDownList()
.Name("Replacement")
.DataTextField("Name")
.DataValueField("SysId")
.DataSource(builder => builder.Read(operationBuilder => operationBuilder.Type(HttpVerbs.Post).Action("Read", "EmployeeDropdown")))
)
</div>
</div>
</div>
<div id="edit_general">
<div id="edit_region">
<p>Region</p>
@(Html.Kendo().DropDownList()
.Name("Region")
.DataTextField("Name")
.DataValueField("SysId")
.DataSource(builder => builder.Read(operationBuilder => operationBuilder.Type(HttpVerbs.Post).Action("Read", "RegionDropdown")))
)
</div>
<div id="edit_language">
<p>Sprache</p>
@(Html.Kendo().DropDownListFor(model => model.Sprache)
.Name("Sprache")
.BindTo(
new List<SelectListItem>() {
new SelectListItem() {
Text = "Deutsch",
Value = "0"
},
new SelectListItem() {
Text = "Englisch",
Value = "1"
}
}
)
)
</div>
<div id="edit_starttime">
<p>Startzeit</p>
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.DefaultBeginTime)
</div>
<div id="edit_pausetime">
<p>Pausenzeit</p>
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.DefaultBreakTime)
</div>
</div>
<div id="edit_worktimes">
@(Html.Kendo().DropDownListFor(model => model.TRSConfiguration.TRSConfigTemplate)
.Name("Zeiterfassungsvorlage")
.BindTo(
new List<SelectListItem>() {
new SelectListItem() {
Text = "Benutzerdefiniert",
Value = "1"
},
new SelectListItem() {
Text = "Vollzeit",
Value = "0"
}
}
)
.Events(e => e.Change("onSelectTRSConfigValue"))
)
<h2>Arbeitszeiten:</h2>
@{
DateTimeDecimalConverter converter = new DateTimeDecimalConverter();
var mondayHours = converter.ConvertDateTimeToDecimal(Model.TRSConfiguration.WorkTimeMondayHours);
var tuesdayHours = converter.ConvertDateTimeToDecimal(Model.TRSConfiguration.WorkTimeTuesdayHours);
var wednesdayHours = converter.ConvertDateTimeToDecimal(Model.TRSConfiguration.WorkTimeWednesdayHours);
var thursdayHours = converter.ConvertDateTimeToDecimal(Model.TRSConfiguration.WorkTimeThursdayHours);
var fridayHours = converter.ConvertDateTimeToDecimal(Model.TRSConfiguration.WorkTimeFridayHours);
<div id="worktimesFull" style="display:none;">
<p class="edit_workday_description">Montag:</p>
<div class="edit_workday_time">@mondayHours h</div>
<p class="edit_workday_description">Dienstag</p>
<div class="edit_workday_time">@tuesdayHours h</div>
<p class="edit_workday_description">Mittwoch</p>
<div class="edit_workday_time"> @wednesdayHours h</div>
<p class="edit_workday_description">Donnerstag</p>
<div class="edit_workday_time">@thursdayHours h</div>
<p class="edit_workday_description">Freitag</p>
<div class="edit_workday_time">@fridayHours h</div>
</div>
<div id="worktimesCustom">
<p class="edit_workday_description">Montag:</p>
<div class="edit_workday_time">
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.WorkTimeMondayHours)
</div>
<p class="edit_workday_description">Dienstag</p>
<div class="edit_workday_time">
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.WorkTimeTuesdayHours)
</div>
<p class="edit_workday_description">Mittwoch</p>
<div class="edit_workday_time">
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.WorkTimeWednesdayHours)
</div>
<p class="edit_workday_description">Donnerstag</p>
<div class="edit_workday_time">
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.WorkTimeThursdayHours)
</div>
<p class="edit_workday_description">Freitag</p>
<div class="edit_workday_time">
@Html.Kendo().TimePickerFor(model => model.TRSConfiguration.WorkTimeFridayHours)
</div>
</div>
</div>
@(Html.Kendo().Button()
.Name("zurueckButton")
.HtmlAttributes(new { type = "button", @class = "button" })
.Content("Zurück")
.Events(ev => ev.Click("zurueckButton")))
@(Html.Kendo().Button()
.Name("neuConfigButton")
.HtmlAttributes(new { type = "button", @class = "button" })
.Content("Neue Zeitkonfiguration")
.Events(ev => ev.Click("neuConfigButton")))
<input type="submit" value="Update" />
</div>
</fieldset>
</main>
}
</body>
</html>
它的控制器看起来像这样:
[HttpGet]
public ActionResult EditTRSConfiguration([DataSourceRequest] DataSourceRequest request, Guid? sysId)
{
Guid empSysId = sysId == null ? Guid.Empty : (Guid)sysId;
if (empSysId == Guid.Empty)
RedirectToAction("Index", "Administration");
EmployeeAdministrationViewModel employeeViewModel;
EmployeeDevice employeeDevice;
TRSConfigurationDevice tRSConfigurationDevice;
TRSConfigurationViewModel tRSConfigurationViewModel;
using (EmployeeManagementConnector empConnector = new EmployeeManagementConnector())
using (TimeRegistrationSystemConnector trsConnector = new TimeRegistrationSystemConnector())
{
employeeDevice = empConnector.LoadEmployees(empSysId, ModelLanguages.deDE).Find(x => x.EmployeeSysId == sysId);
tRSConfigurationDevice = trsConnector.LoadTRSConfigurationDevices().Find(x => x.EmployeeSysId == sysId);
TRSAccountDevice trsDevice = trsConnector.LoadAccountDevice(empSysId);
AdministrationMapper mapper = new AdministrationMapper();
//Getting the needed devices and Mapper
tRSConfigurationViewModel = mapper.Map(tRSConfigurationDevice);
List<EmployeeDropdownDevice> replacements = empConnector.LoadOtherEmployees(empSysId, ModelLanguages.deDE);
EmployeeDropdownViewModel replacement = mapper.Map(replacements[0]);
employeeViewModel = mapper.Map(tRSConfigurationViewModel, trsDevice, employeeDevice, replacement);
}
return PartialView(employeeViewModel);
}
[HttpPost]
public ActionResult EditTRSConfiguration(EmployeeAdministrationViewModel empViewodel, Guid? sysId)
{
return PartialView(employeeViewModel);
}
但问题是,我没有成为任何变更数据。 我可以在页面上更改的所有数据都在输出中只是“null”。
有谁知道如何获取数据?
如果有人可以帮我解决问题,那会很棒。最好的问候
答案 0 :(得分:0)
您可以使用BIND建模您在控制器中收到的数据:
public ActionResult EditTRSConfiguration([Bind(Include = "TRSConfiguration,Sprache")] Models.EmployeeAdministrationViewModel Employee){
}
在那里,您可以指定您将从视图中接收哪些属性