I am creating an MVC web application in .net that has 2 drop down lists with a list of timestamps. I am able to populate those drop downs successfully using linq query from the model of IEnumerable<> (.edmx).
@model IEnumerable<Softwares>
@{ var times = from ts in Model select ts.Distinct() }
<select id="time1">
@foreach(var item in times)
{ <option> @item </option> }
</select>
<select id="time2">
@foreach(var item in times)
{ <option> @item </option> }
</select>
<button id="compare> Compare </button>
I need to take these 2 timestamps as parameters into an sql query. When debugging it seems that I am able to pass the timestamps back to the Action Result in my controller, into the model to as parameters and then back to my Controller.
<script>
var t1 = $("#time1").val();
var t2 = $("#time2").val();
$(document).ready(function(){
$("#compare").click(){
$.post("Home/CompareSoftware", {time1 = t1, time2 = t2},
function(data){
alert(data)
});
</script>
My problem is getting the value from the controller and pushing it back to the view formatted as a table. I'm not quite sure what the "data" is because it seems like it is my t1 and t2 that I'm passing back to my Controller action CompareSoftware. I try just getting it to show up in an alert box but when I run this script and click compare I get an unsuccessful message. Please note that I am writing this code from memory so it might not be exactly correct here.
Here is my controller:
public ActionResult CompareSoftware(string time1, string time2){
time1 = t1; time2 = t2; Convert to TimeStamp.
var retVal = Models.CompareSoftware(t1, t2)
return View(retVal)
}
My model takes in 2 timestamps and returns a List class that has 4 fields. My code is paraphrased above but when debugging I am able to get a return value from my model and push it back to the Controller. How to I display this information to the view? I'm guessing this ajax post returns JSON data and I need to convert that to my view? I'm not exactly sure.