1
Answer

Unable to bind Cascading Dropdowns - jQuery AJAX

Photo of Learn Avid

Learn Avid

8y
332
1
My DB consists of Regions, Divisions & States. My application (ASP.NET MVC) application uses entityframework to bind data to DropDown.
  • Created Action to bind Regions by default.
  • Created Action with RegionId as parameter to retrive Divisions
  1. [HttpGet]  
  2.        public JsonResult GetDivisionsByRegions(string regionID = "")  
  3.        {  
  4.            try  
  5.            {  
  6.                List<Division> allDivisions = new List<Division>();  
  7.                int ID = 0;  
  8.                if (int.TryParse(regionID, out ID))  
  9.                {  
  10.                    using (GeoEntities data = new GeoEntities())  
  11.                    {  
  12.                        allDivisions = data.Divisions.Where(div => div.RegionID == ID).OrderBy(div => div.DivisionID).ToList();  
  13.                    }  
  14.                }  
  15.                if (Request.IsAjaxRequest())  
  16.                {  
  17.                    return new JsonResult  
  18.                    {  
  19.                        Data = allDivisions,  
  20.                        JsonRequestBehavior = JsonRequestBehavior.AllowGet  
  21.                    };  
  22.                }  
  23.                else  
  24.                {  
  25.                    return new JsonResult  
  26.                    {  
  27.                        Data = "Invalid Data",  
  28.                        JsonRequestBehavior = JsonRequestBehavior.AllowGet  
  29.                    };  
  30.                }  
  31.            }  
  32.            finally  
  33.            {  
  34.            }  
  35.        } 
  • jQuery AJAX call to GET data from & bind to Dropdown.
  1. <script type="text/javascript">  
  2.     $(document).ready(function () {  
  3.         $('#RegionID').change(function () {  
  4.             var regionID = parseInt($('#RegionID').val());  
  5.             if (!isNaN(regionID)) {  
  6.                 var ddDivision = $('#DivisionID');  
  7.                 ddDivision.empty();  
  8.                 ddDivision.append($("<option></option>").val("").html("Select Division"));  
  9.                 $.ajax({  
  10.                     url: "@Url.Action("GetDivisionsByRegions","GetGeoData")",  
  11.                     type: "GET",  
  12.                     data: { regionID: regionID },  
  13.                     dataType: "json",  
  14.                     success: function (data) {  
  15.                         $.each(data, function (i, value) {  
  16.                             ddDivision.append(  
  17.                                 $('<option></option>').val(value.DivisionID).html(value.DivisionName)  
  18.                                 );  
  19.                         });  
  20.                     },  
  21.                     error: function () {  
  22.                         alert('Sorry!! Error');  
  23.                     }  
  24.   
  25.                 });  
  26.   
  27.             }  
  28.         });  
  29.     });  
  30. </script> 
  • Able to get data from entity.


  • Error when bindig to Division drop down


Please help me out..

Answers (1)

0
Photo of Shibly  Sadik
NA 139 47.5k 9y
Thanks for your answersir..please look at my code below:
 
//Model 
public class PayPalModel
{
[Key]
public string cmd { get; set; }
public string business { get; set; }
public string no_shipping { get; set; }
public string @return { get; set; }
public string cancel_return { get; set; }
public string notify_url { get; set; }
public string currency_code { get; set; }
public string item_name { get; set; }
public string amount { get; set; }
public string actionURL { get; set; }
public PayPalModel(bool useSandbox)
{
this.cmd = "_xclick ";
this.business =
ConfigurationManager.AppSettings
["business "];
this.cancel_return =
ConfigurationManager.AppSettings
["cancel_return "];
this.@return =
ConfigurationManager.AppSettings
["return "];
if (useSandbox)
{
this.actionURL =
ConfigurationManager.AppSettings
["test_url"];
}
else
{
this.actionURL =
ConfigurationManager.AppSettings
["Prod_url"];
}
this.notify_url =
ConfigurationManager.AppSettings
["notify_url "];
this.currency_code =
ConfigurationManager.AppSettings
["currency_code "];
}
}
 
//Controller 
 
public ActionResult ValidateCommand(string
product, string totalPrice)
{
bool useSandbox =
Convert.ToBoolean
(ConfigurationManager.AppSettings
[" IsSandbox "]);
var paypal = new PayPalModel
(useSandbox);
paypal.cmd = "_xclick";
paypal.item_name = product;
paypal.amount = totalPrice;
return View(paypal);
}
 
Where is the problem?? 
0
Photo of Blackbarbie Bb
NA 104 5 9y
Long back i have written in c#
 

Before testing my code, I log in the PayPal Developer Central and then I launch the SandBox for the seller’s email

( sparkingboss@si.com ).

I would like to get some help to find out why my code is not working in the PayPal SandBox.

It returns an error message:

“We cannot process this transaction because there is a problem with the PayPal email address supplied by the seller. Please contact the seller to solve the problem.”

The strange thing is that I used the same variables and its values and the same email addresses in the PayPalTech – Testing page ( http://paypaltech.com/Stephen/test/index.htm ) and it works.

Here is the relevant code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Create the PayPal redirect location for Buy Now

string redirect = "";

redirect += "https://www.sandbox.paypal.com/cgi-bin/webscr?busines=sparkingboss@si.com";

redirect += "&cmd=_xclick";

redirect += "&invoice=" + orderId;

redirect += "&item_name=" + productName;

redirect += "&item_number=" + productID;

redirect += "&amount=" + price;

redirect += "&quantity=" + quantity;

redirect += "&currency_=USD";

redirect += "&return=http://83.35.154.61/SI/PDT_CustomerReturn.aspx";

redirect += "&cancel_return=http://83.35.154.61/SI/Cancel.aspx";

redirect += "&rm=2";// means method=POST

redirect += "notify_url=http://83.35.154.61/SI/IpnHandler.aspx"; //receive IPN

redirect += "&no-shipping=1"; // not asked for shipping details

redirect += "&first_name=" + firstname;

redirect += "&last_name=" + lastname;

//redirect += "&email=" + email;

redirect += "&email=stephen@a_web_site.com";

// Redirect to the payment page

Response.Redirect(redirect);

 
hope it would resolve your problem,ensure u have properly provided amount,price string as formatted in their code