I have a from like below
<form action="/" method="get">
<input type="radio" name="sort" value="date-desc" checked>
<input type="radio" name="sort" value="price-desc">
<input type="radio" name="sort" value="price-asc">
<input type="radio" name="sort" value="like-desc">
<input type="radio" name="sort" value="like-asc">
<input type="checkbox" name="show-discount">
<input type="checkbox" name="show-new">
<input type="submit" class="btn btn-default" value="Search">
</form>
it returns url like: <site>?sort=date-desc&show-discount=on&show-new=on
i want to bind it to the controller action, the action is like below:
public ActionResult Index([Bind(Prefix = "sort")]string Sort,
[Bind(Prefix = "show-discount")]bool? ShowDiscount = null,
[Bind(Prefix = "show-new")]bool? ShowNew = null)
{
}
the problem is ShowDiscount and ShowNew parameter always null (didn't bound properly).
i think the problem caused by the checkbox when checked it written as cb-name=on instead of cb-name=true. and also when the checkbox unchecked it will not written on the url.
is there a proper way to do this?
and is there a way to map Sort parameter to enumeration?