Passing Object From Controller to JavaScript JQuery

Posted by TMan on Stack Overflow See other posts from Stack Overflow or by TMan
Published on 2012-04-14T05:11:03Z Indexed on 2012/04/14 5:29 UTC
Read the original article Hit count: 197

Filed under:
|
|
|

This is driving me crazy. All I'm trying to do is to pass in a Id to a ActionMethod which is working and have an Object be returned to the javascript. Then in javascript, I want to be able to say something like..Objec.Property, ie/ Student.Name, or Student.GPA.

Any help is appreciated. I tried json but couldn't get that to work either.

ActionResult:

[AcceptVerbs(HttpVerbs.Get)]
public Epic GetEpicPropertyDetails(int id)
{  
   var Epictemplist = epicRepository.Select().Where(x => x.Id.Equals(id));
   return Epictemplist.SingleOrDefault();
}

javascript:

<script type="text/javascript">
   $(document).ready(function () {
     $(".ListBoxClass").click(function (event) {
       var selectedid = $(this).find("option:selected").val();
       event.preventDefault();
       $.get("/Estimate/GetEpicPropertyDetails", { id: selectedid }, function (result) {
         $(".TimeClass").val(result);
       });
     });
   });
</script>

result.Name is obviously wrong I just dont know how to call this the right way.

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript