Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
This in is my 4th Question on same topic but no one can help here.

I am in trouble about adding button function in ASP.NET MVC.

I am trying to send first row data to controller and and want return for same view for new row.

he show isAllValid is works successfully but AJAX topic is not works

What I have tried:

$(document).ready(function () {
				$("#add").click(function () {
					var isAllValid = true;
					if ($('#ProdID').val() == "0") {
						isAllValid = false;
						$('#ProdID').siblings('span.error').css('visibility', 'visible');
					}
					else {
						$('#ProdID').siblings('span.error').css('visibility', 'hidden');
					}
					if ($('#ProductGstCode').val() == "") {
						isAllValid = false;
						$('#ProductGstCode').siblings('span.error').css('visibility', 'visible');
					}
					else {
						$('#ProductGstCode').siblings('span.error').css('visibility', 'hidden');
					}
					if ($('#PerchesQty').val() == "0") {
						isAllValid = false;
						$('#PerchesQty').siblings('span.error').css('visibility', 'visible');
					}
					else {
						$('#PerchesQty').siblings('span.error').css('visibility', 'hidden');
					}
					if ($('#PerchesRate').val() == "0.00") {
						isAllValid = false;
						$('#PerchesRate').siblings('span.error').css('visibility', 'visible');
					}
					else {
						$('#PerchesRate').siblings('span.error').css('visibility', 'hidden');
					}
					if (isAllValid) {
						alert("ok1")
						$.ajax({
							url: "/Perchus/PostMethod",
							dataType: 'json',
							data: {
								ProductId: $("#ProdID").val(),
								Gst: $("#ProductGstCode").val(),
								PerchesQty: $("#PerchesQty").val(),
								PerchesRate: ("#PerchesRate").val()
							},
							type: "POST",
							cache: false,
							success: function (data)
							{
								//want to return data as not boolean but string here
								if (data == "success") {
									alert(isAllValid);
								}
								else {
									alert("false")
								}
							},
							error: function () {
								alert("Error")
							}
						});
					}
					else {
						alert("NOt work")
					}
				});
Posted
Updated 8-Feb-19 1:37am
v3
Comments
Sunasara Imdadhusen 8-Feb-19 5:49am    
Can you let us know what was the issue?
yogesh vaidya 8-Feb-19 6:46am    
ajax topic is not working ,
before the ajax all things is working properly in
if (isAllValid) {
alert("ok1")

reverts the message 'ok1' but there after nun of action getting from ajax
mins some mistake is in ajax but i cant understand ,

$.ajax({
url: "/Perchus/PostMethod",
dataType: 'json',
data: {
ProductId: $("#ProdID").val(),
Gst: $("#ProductGstCode").val(),
PerchesQty: $("#PerchesQty").val(),
PerchesRate: ("#PerchesRate").val()
},
type: "POST",
cache: false,
success: function (data)
{
//want to return data as not boolean but string here
if (data == "success") {
alert(isAllValid);
}
else {
alert("false")
}
},
error: function () {
alert("Error")
}
});
}


its should not reports to controller

[HttpPost]
public JsonResult UpdateUsersDetail(string Gst,int ProductId)
{

var js = new JavaScriptSerializer();
PerchesDetail[] user = js.Deserialize<PerchesDetail[]>(usersJson);


return Json("User Details are updated");
MadMyche 8-Feb-19 7:33am    
Well maybe you should use the correct Tags>: your problem is neither ASPNET nor MVC related. It is simply a JavaScript/JQuery coding issue
Sunasara Imdadhusen 8-Feb-19 8:16am    
Can you check what is the issue with ajax using Browsers Developer tool (Console)?
Richard Deeming 12-Feb-19 13:23pm    
"This in is my 4th Question on same topic but no one can help here."

Firstly, consider the fact that nobody is helping you because you haven't provided enough information. Multiple requests for clarification go unanswered.

Secondly, the regular derogatory comments about us - "no one can help here", "no one answering here", etc. - aren't helping. You've essentially walked into a room, slammed your fist on the table, and shouted "You're all a bunch of idiots! Now answer my question." - not a great way to encourage people to help you!

And finally, if you don't get an answer to your question, DO NOT repost the same question again. Instead, go back to your original question, click the green "Improve question" link, and add more information about the problem you're facing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900