Hi AliYilmaz,
Refer below sample.
Controller
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Talepler(FormCollection formCollection)
{
bool chkeco = false, chkbuss = false;
string chkecoValue = "";
string chkbussValue = "";
if (!string.IsNullOrEmpty(formCollection["chkeco"])) { chkeco = true; }
if (!string.IsNullOrEmpty(formCollection["chkbuss"])) { chkbuss = true; }
if (chkeco) { chkecoValue = formCollection["chkeco"]; }
if (chkbuss) { chkbussValue = formCollection["chkbuss"]; }
return View("Index");
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@using (Html.BeginForm("Talepler", "Home", FormMethod.Post))
{
<div class="filter">
<h5><i class="fa fa-list"></i> Class</h5>
<ul>
<li>
<input id="chk" type="checkbox" name="chkeco" value="1" />Economy
</li>
<li>
<input type="checkbox" name="chkbuss" value="2" />Business
</li>
</ul>
</div>
<input type="submit" value="Submit" />
}
</div>
</body>
</html>
It’s pretty simple. Checkbox has a name and value property. If checked the name and value are submitted, if not checked it’s not submitted. So in mvc the name is used to map to a parameter name (Here I used FormCollection). If you made the name "chkeco" then in FormCollection you need to access with the name "chkeco" to check its checked or not. If nut checked you will get null. If checked you will get the value as well as in the sample code.