【发布时间】:2016-02-11 03:15:47
【问题描述】:
在我的 c# WebApp 中创建运行良好的复选框时遇到问题。 有人可以向我展示一个带有模型的工作版本以及视图和控制器的外观。
型号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TEST.Models
{
public class Checkbox
{
public bool IsChecked { get; set; }
}
}
查看:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm())
{
@Html.CheckBox()
}
控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TEST.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
}
}
【问题讨论】:
-
显示你的代码并指出什么不工作
-
@Html.CheckBox("check", true, new {id = dir }),这就是我现在正在尝试的,没有模型
-
您需要一个具有
boolean属性的模型——比如bool IsSelected,然后在视图中使用@Html.CheckBoxFor(m => m.IsSelected),当您发布表单时,IsSelected的值将是@ 987654328@ offalse基于复选框的选中状态 -
我尝试联系我的控制器并遇到问题。我必须给他什么参数?例如:public AvtionResult IsChecked (???) { if (??? = true) { } }
-
显示您的代码。我们不是通灵者。
标签: c# model-view-controller checkbox web-applications