MaineOne is right. If you look at your form's action attribute "product/update" that is the URL that will be invoked. If you want the checkbox state to be passed in the URL I think you'll need some javascript to put it there right before the form submits,
possibly using the onsubmit event of the form.
Otherwise, just use what MaineOne said in the server side and remove that action parameter.
That doesn't matter for the problem if not getting the value as a parameter to the action method. I was assuming you had a POST there anyway. With POST in your form you will be able to verify the checkbox presence using the Request.Form["checkbox_name"].
To get the checkbox state passed as a method parameter I still think you will need to put it in the form's action before posting.
The conversion error is because you're trying to convert the default checkbox value of "on" or "off" to a boolean. To get this to work, you need to set a value on the checkbox of "1" or "true" and then do some testing to make sure it's been selected:
I have strong opinion that Controller MUST NOT acceess Request.Form anyway this is interface.
I have controller with simple and testable signature. I write controller and than view not the contrary
public void Step2(
string Name, int Age, bool
skip_step )
and want be possible provide fields from html form to this controller.
in signature above int field succesfull provided to controller ( except cases when not int values entered - this interesting case too, but about it later. )
and chackebox i think must be converted to bool (i think it very logical =)) )
so i want have way for it, some kind of converters etc.
Now I have one more or less appropriate way:
use signature:
public void Step2(
string Name, int Age, string
skip_step )
and check that skip_step is not null
{
if ( skip_step != null )
// checked
else
// unchecked
I have strong opinion that Controller MUST NOT acceess Request.Form anyway this is interface.
Are you saying that you think using Request.Form is always to be avoided?? I hope not. How would you handle form posts with several textareas and file uploads for example?
mogadanez
Member
73 Points
49 Posts
[BUG]Value from checkbox do not handle as parameter
Dec 23, 2007 08:08 PM|LINK
have view:
controller:
bugs
MaineOne
Contributor
2087 Points
469 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 23, 2007 09:46 PM|LINK
I do not know much C# but If you want the value of the Checkbox all you should need to do is use Request("include_details")
Sub Update()
Dim xxx as Boolean = Request("include_details")
End Sub
In C# ( don't know the Dim Equivalant off the top of my head, but this should give you an Idea)
Public Void Update()
{
xxx = Request["include_details"]
}
sergiopereir...
Member
227 Points
61 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 23, 2007 09:53 PM|LINK
MaineOne is right. If you look at your form's action attribute "product/update" that is the URL that will be invoked. If you want the checkbox state to be passed in the URL I think you'll need some javascript to put it there right before the form submits, possibly using the onsubmit event of the form.
Otherwise, just use what MaineOne said in the server side and remove that action parameter.
Sergio Pereira
http://devlicio.us/blogs/sergio_pereira/
mogadanez
Member
73 Points
49 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 06:01 AM|LINK
i use POST, not GET.
sorry, missed:
<form action='product/update' method="POST">
...
sergiopereir...
Member
227 Points
61 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 03:49 PM|LINK
That doesn't matter for the problem if not getting the value as a parameter to the action method. I was assuming you had a POST there anyway. With POST in your form you will be able to verify the checkbox presence using the Request.Form["checkbox_name"].
To get the checkbox state passed as a method parameter I still think you will need to put it in the form's action before posting.
Sergio Pereira
http://devlicio.us/blogs/sergio_pereira/
robconery
Participant
852 Points
195 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 05:59 PM|LINK
The conversion error is because you're trying to convert the default checkbox value of "on" or "off" to a boolean. To get this to work, you need to set a value on the checkbox of "1" or "true" and then do some testing to make sure it's been selected:
mogadanez
Member
73 Points
49 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 06:30 PM|LINK
I have strong opinion that Controller MUST NOT acceess Request.Form anyway this is interface.
I have controller with simple and testable signature. I write controller and than view not the contrary
public void Step2( string Name, int Age, bool skip_step )and want be possible provide fields from html form to this controller.
in signature above int field succesfull provided to controller ( except cases when not int values entered - this interesting case too, but about it later. )
and chackebox i think must be converted to bool (i think it very logical =)) )
so i want have way for it, some kind of converters etc.
Now I have one more or less appropriate way:
use signature:
public void Step2( string Name, int Age, string skip_step )
and check that skip_step is not null
{
if ( skip_step != null )
// checked
else
// unchecked
}
Jonathan Hol...
Member
41 Points
11 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 07:03 PM|LINK
http://www.squaredroot.com/post/2007/12/MVC-Checkboxes-Complaint.aspx
This blog had a pretty good rundown on how the current CTP handles checkboxes.
sergiopereir...
Member
227 Points
61 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 07:43 PM|LINK
Are you saying that you think using Request.Form is always to be avoided?? I hope not. How would you handle form posts with several textareas and file uploads for example?
Sergio Pereira
http://devlicio.us/blogs/sergio_pereira/
mogadanez
Member
73 Points
49 Posts
Re: [BUG]Value from checkbox do not handle as parameter
Dec 24, 2007 08:19 PM|LINK
Thanks, Troy Goode has the same solution as me - provide string param and check for null
[ControllerAction]
public void Authenticate( string userName, string password, string rememberMe )
{
if( rememberMe != null ){ ... }
}