vendredi 21 août 2015

how to make ajax call to get partial view contains javascript?

I am trying to make an ajax call to get data and to Modify DOM.

here is my controller/ action looks like

public ActionResult Index(int id)
// some code
return PartialView(Custom Object);
here is my Index View looks like

@Model CustomObject
    @foreach(loop thru Model)
// add some other elements
<script>some script</script>
<script>variable = '<div></div>'</script>

here is main view code

<script>var variable ='';</script>
<tbody id="tbodyId">

here is my Ajax Call. I was trying to do

function test(id){

My issue is from the above ajax call it is not appending the script element from partial view.

I tried different ways from javascript side. But, im not sure whether im doing it right way or not. So, i need some suggestions from leads.

here is the other way i tried. but no luck

var scriptElement = document.createElement('script');
            scriptElement.innerHTML = $('#tbodyId').last().html();

any help would be appreciated. Thanks!!

Aucun commentaire:

Enregistrer un commentaire