我有一个从控制器发送数据到视图的模块。它有多行,并且可以按我的意愿正确显示。现在,在用户进行了一些更改后,我再次尝试在 actionresult 的帮助下保存数据库中的更改。但是当我尝试获取值时,它说我的模型为空/空,但它不是...我没有得到问题所在...提前谢谢...
这是我的模型:
public class ManageAppsModel
{
public string appname { get; set; }
public int id { get; set; }
public bool chkbillboard { get; set; }
}
这是我的看法:
@model IEnumerable<Nd.Models.ManageAppsModel>
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<br />
<h2 style="color:#80afdd;font-size:14px;">
<strong> List of Existing Apps:</strong>
</h2>
<br />
<div class="section-copy">
<table>
@foreach (var item in Model)
{
<tr>
@if (Context.User.Identity.Name == "admin")
{
<td style="width:50px;">
@if (@item.chkbillboard == true)
{
<input name ="chk1" class="myCheckbox" type="checkbox" value="@item.chkbillboard" checked="checked" />
}
else
{
<input name ="chk2" class="myCheckbox" id="chkbox" type="checkbox" value="@item.chkbillboard" onclick="return chkbox();" />
}
</td>
}
<td style="width:200px;">
@item.appname
</td>
<td style="width:50px;">
@Html.ActionLink("Edit", "UpdateAPIForm", new { @id = item.id, appname = item.appname })
</td>
</tr>
}
</table>
</div>
<br/><br/>
if (Context.User.Identity.Name == "admin")
{
<div>
<input type="submit" name="Upload" value="Upload new flash info message" />
</div>
}
}
这是我的行动结果:
[Authorize]
public ActionResult ManageApps(String username)
{
var a = HttpContext.User.Identity.Name;
var context = new ndCorp_SiteEntities();
if (a == "admin")
{
var viewModel1 = from dc in context.DevContactInfoes
join dm in context.DevMarketplaceInfoes on dc.AppName equals dm.AppName
select new ManageAppsModel { appname = dc.AppName, id = dc.SNo, chkbillboard = dc.billboard.Value }
;
return View( viewModel1 );
}
else
{
var viewModel = from du in context.DevUserInfoes
join dc in context.DevContactInfoes on du.UserName equals dc.UserName
join dm in context.DevMarketplaceInfoes on dc.AppName equals dm.AppName
where du.UserName == a
select new ManageAppsModel { appname = dc.AppName, id = dc.SNo };
return View(viewModel);
}
}
[Authorize]
[HttpPost]
public ActionResult ManageApps(IEnumerable<ManageAppsModel> apps)
{
var user = HttpContext.User.Identity.Name;
var context = new ndCorp_SiteEntities();
foreach (var ManageAppsModel in apps)
{
if (ManageAppsModel.chkbillboard == true)
{
Response.Write("hello");
}
}
return RedirectToAction("ManageApps", new { username = user });
}