March 18, 2013

jQuery syntax error?

Question by user1977591

I found an example here on stackoverflow that I am trying to recreate and use a solution.
here is the link to the example: Refreshing Partial View in MVC 3

what is wrong with my syntax?

function RefreshPartial() {
        $('#invited-teams').load('/Challenge/GetInvitedTeams', {Model.ChallengeId});
    }   

will this work? or does it need to have the curly brackets?

function RefreshPartial() {
        $('#invited-teams').load('/Challenge/GetInvitedTeams', "<%= Model.ChallengeId %>" );
    }   

UPDATE:

 function RefreshPartial() {
        $('#invited-teams').load('/Challenge/GetInvitedTeams',
            {'paramname' : <%:Model.ChallengeId %> });
    }   

my partial view:

            <div id="invited-teams">
                <% Html.RenderPartial("InvitedTeams", Model.InvitedTeams); %>
            </div>

So, this is what my refreshPartial method is looking like:

function RefreshPartial() {
        alert("in refresh partial");
        alert("<%:Model.ChallengeId %>");
        $('#invited-teams').load('/Challenge/GetInvitedTeams', { 
            'paramname': '<%:Model.ChallengeId %>'
        });


    }

it alerts both alerts correctly, with the 2nd one having the correct ChallengeID. The page is still going blank though. hmm..

Answer by Starx

Your function does not specify a parameter name.

function RefreshPartial() {
    $('#invited-teams').load('/Challenge/GetInvitedTeams', {
       'paramname' :'<%:Model.ChallengeId %>'//Or your ASP wrapper here
    });
}  

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!