hi thnx for ur reply but the problem is not that , i know that i can get the name of my buton but it's an input of image not an input of submit button and it's so different .because of that i posted this url :http://stackoverflow.com/questions/1619272/catching-input-image-value-in-controller-using-ie on
wich they says that is not possible to get the name of image button (<input type='image'..../> and that works in firefox not IE .i need solution to get the name of my input image in IE :
My controller :
[HttpPost]
public ActionResult PieceTraiementType(PieceDto piece, string btnSubmit)
{
switch (btnSubmit)
{
case "Ajouter":
_adminTraitementBusiness.AddPieceTraiementType(piece);
break;
case "Supprimer":
_adminTraitementBusiness.DeleteTraitementTypePiece(piece.TraitementTypeId, piece.TypePieceId);
break;
}
return RedirectToAction("GetDetailTypeTraitement", new { traitementTypeId = piece.TraitementTypeId });
}
when i click on my image the (string btnSubmit) is null.
<input type="image" id="btnSubmit" name="btnSubmit" value="next" src="..." />
....
<script type="text/javascript" language="javascript">
//jQuery
//can replace with ur form id
$('form').submit(function () {
var value = $('#btnSubmit').val();
var input = $("<input>").attr("type", "hidden").attr("name", "btnSubmit").val(value);
$(this).append($(input));
});
</script>
as per the w3c spec, input type=image post two values. name.x=xcord and name.y=ycord
to use MVC binding, use a custom class.
public class ImageSubmit
{
public int x {get; set;} // note lower case
public int y {get; set;}
}
public MyModel
{
public ImageSubmit Save {get; set;}
}
elminianimer...
Member
1 Points
32 Posts
Input Image problem
Jul 26, 2012 06:20 PM|LINK
How do I catch the value of an image button in a controller. I have:
In my controller I have
{ ...CPrakash82
All-Star
18270 Points
2839 Posts
Re: Input Image problem
Jul 27, 2012 01:21 AM|LINK
You need to have the action method with matching button name and it will bind it automatically.
<input type="image" id="btnSubmit" name="btnSubmit" value="next" src="..." />
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PieceTraiementType( string btnSubmit) { ...}
In this action method parameter btnSubmit will have value 'next'.
Look for more discussion here.
http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework
elminianimer...
Member
1 Points
32 Posts
Re: Input Image problem
Jul 27, 2012 09:42 AM|LINK
hi thnx for ur reply but the problem is not that , i know that i can get the name of my buton but it's an input of image not an input of submit button and it's so different .because of that i posted this url :http://stackoverflow.com/questions/1619272/catching-input-image-value-in-controller-using-ie on wich they says that is not possible to get the name of image button (<input type='image'..../> and that works in firefox not IE .i need solution to get the name of my input image in IE :
My controller :
[HttpPost] public ActionResult PieceTraiementType(PieceDto piece, string btnSubmit) { switch (btnSubmit) { case "Ajouter": _adminTraitementBusiness.AddPieceTraiementType(piece); break; case "Supprimer": _adminTraitementBusiness.DeleteTraitementTypePiece(piece.TraitementTypeId, piece.TypePieceId); break; } return RedirectToAction("GetDetailTypeTraitement", new { traitementTypeId = piece.TraitementTypeId }); }when i click on my image the (string btnSubmit) is null.
Bieters
Member
229 Points
48 Posts
Re: Input Image problem
Jul 27, 2012 10:23 AM|LINK
Attach jquery to the button, get the attribute values of the button and submit yourself
elminianimer...
Member
1 Points
32 Posts
Re: Input Image problem
Aug 03, 2012 11:36 AM|LINK
Pliz can u help me to do this?? :(
ossprologix
Member
392 Points
127 Posts
Re: Input Image problem
Aug 03, 2012 12:01 PM|LINK
wud it be helpful if u cud use hidden input
ossprologix
Member
392 Points
127 Posts
Re: Input Image problem
Aug 03, 2012 12:13 PM|LINK
dirty solution wud be
In ur view
<input type="image" id="btnSubmit" name="btnSubmit" value="next" src="..." /> .... <script type="text/javascript" language="javascript"> //jQuery //can replace with ur form id $('form').submit(function () { var value = $('#btnSubmit').val(); var input = $("<input>").attr("type", "hidden").attr("name", "btnSubmit").val(value); $(this).append($(input)); }); </script>hope this helps
cyberbud
Contributor
3298 Points
551 Posts
Re: Input Image problem
Aug 03, 2012 12:34 PM|LINK
I'm assuming that you have two buttons in your page but they need to perform different action based on the button being clicked.
So Ammending what ossprologix just said
<input type="image" id="btnSubmit" name="btnSubmit" value="Supprimer" src="..." onClick="interceptAndSubmit()" /> <input type="image" id="btnSubmit" name="btnSubmit" value="Ajouter" src="..." onClick="interceptAndSubmit()" /> <script type="text/javascript" language="javascript"> function interceptAndSubmit(){ var btnVal=$(this).val(); var input = $("<input>").attr("type", "hidden").attr("name", "btnSubmit").val(btnVal); $('form').append($(input)); $('form').submit(); } </script>MCP(.net 3.5)
Nepal
ishwor.cyberbudsonline.com
elminianimer...
Member
1 Points
32 Posts
Re: Input Image problem
Aug 03, 2012 02:00 PM|LINK
i will try this now
bruce (sqlwo...
All-Star
36836 Points
5443 Posts
Re: Input Image problem
Aug 03, 2012 03:46 PM|LINK
as per the w3c spec, input type=image post two values. name.x=xcord and name.y=ycord
to use MVC binding, use a custom class.
public class ImageSubmit { public int x {get; set;} // note lower case public int y {get; set;} } public MyModel { public ImageSubmit Save {get; set;} }