This is my code behind:
This is my KO Script:
this is the result when I click my submit button
I there anything wrong with my code?
This is my code behind:
This is my KO Script:
this is the result when I click my submit button
I there anything wrong with my code?
I have downloaded your solution and got it working
In App_Start\RouteConfig.cs
you have the following line which needs to be removed:
settings.AutoRedirectMode = RedirectMode.Permanent;
Also your web method needs to be static
In App_Start\RouteConfig.cs
Change
settings.AutoRedirectMode = RedirectMode.Permanent;
to
settings.AutoRedirectMode = RedirectMode.Off;
If the web method is not static in code behind, it will not work.
If you really want to continue using code behind, you can do so by creating a static method.
Example:
public class Customer
{
public string CustomerId { get; set; }
public string ContactName { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string PostalCode { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
}
[WebMethod]
public static List<Customer> GetCustomers()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 * FROM Customers"))
{
cmd.Connection = con;
List<Customer> customers = new List<Customer>();
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(new Customer
{
CustomerId = sdr["CustomerId"].ToString(),
ContactName = sdr["ContactName"].ToString(),
City = sdr["City"].ToString(),
Country = sdr["Country"].ToString(),
PostalCode = sdr["PostalCode"].ToString(),
Phone = sdr["Phone"].ToString(),
Fax = sdr["Fax"].ToString(),
});
}
}
con.Close();
return customers;
}
}
}
}
An easier alternative is to create a webservice (.ASMX) using instance methods.