是否有可能转换formcollection
为已知的"模型"?
[HttpPost]
public ActionResult Settings(FormCollection fc)
{
var model=(Student)fc; // Error: Can't convert type 'FormCollection' to 'Student'
}
Run Code Online (Sandbox Code Playgroud)
注意:由于某些原因,我不能使用ViewModel.
这是我的代码VIEW:Settings.cshtml
@model MediaLibrarySetting
@{
ViewBag.Title = "Library Settings";
var extensions = (IQueryable<MediaLibrarySetting>)(ViewBag.Data);
}
@helper EntriForm(MediaLibrarySetting cmodel)
{
<form action='@Url.Action("Settings", "MediaLibrary")' id='MLS-@cmodel.MediaLibrarySettingID' method='post' style='min-width:170px' class="smart-form">
@Html.HiddenFor(model => cmodel.MediaLibrarySettingID)
<div class='input'>
<label>
New File Extension:@Html.TextBoxFor(model => cmodel.Extention, new { @class = "form-control style-0" })
</label>
<small>@Html.ValidationMessageFor(model => cmodel.Extention)</small>
</div>
<div>
<label class='checkbox'>
@Html.CheckBoxFor(model => cmodel.AllowUpload, new { @class = "style-0" })<i></i> …
Run Code Online (Sandbox Code Playgroud)