ITsolutionWizard
asked on
mvc, jquery
Below codes: How can i drop return list into <div id="testarea"></div>?
[HttpPost]
public ActionResult TestList(string state, string carrier)
{
List<Models.Quote> qList = new List<Models.Quote>();
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand("", connection))
{
connection.Open();
command.CommandText = "SELECT * FROM [QT_Health] where State=@state and Carrier=@carrier and ApplicantTypeID=1 and (minage>=0 and maxage <=29) ";
command.Parameters.AddWithValue("@carrier", "abc");
command.Parameters.AddWithValue("@state", "AA");
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
qList.Add(
new Models.Quote
{
planName = reader["PlanName"].ToString(),
carrier = reader["Carrier"].ToString(),
benefitAmount = reader["Benefit"].ToString(),
premiumAmount = reader["Premium"].ToString(),
maxAge = reader["MinAge"].ToString(),
minAge = reader["MaxAge"].ToString(),
metal = reader["Metal"].ToString()
});
}
}
}
return View(qList);
}
<script>
window.onload = function() {
Quote();
};
function Quote()
{
$.ajax({
url: "/Home/TestList", //"/Home/Test01a",
datatype: "text",
data: { 'state': 'CA', 'carrier': '1' }, //exactly same format as controller
type: "POST",
success: function (data) {
alert("Success");
},
error: function () {
$("#testarea").html("ERROR");
}
});
}
</script>
<div id="testarea"></div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are returning text so I am going to assume it is HTML you are returning. In which case just do this
success: function (data) {
$('#testarea').html(data);
},
Where is <div id="testarea"></div> defined
What does qlist look like when it is returned