0

SO a quick question: I would like to execute a certain Jquery function in my view.

I have a function

function doSomething() { $('#page'). ... }); }

Only when @if (TempData["check"] != null) { ... then the function should be called.

In all examples I can find online a function can either be called from the (document).ready function or from pressing a button.

My question: how dou you execute a jquery from a dhtml

I am using MVC4 with razor

2 Answers 2

1

Is this what you're looking for:

In the HTML portion of the page:

<script>
    $(document).ready(function() 
        ...
    });
</script>

?

make sure you're also loading your jquery file somewhere in that page's DOM. Adding

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

right above the opening script tag above should suffice.

Sign up to request clarification or add additional context in comments.

Comments

0

actually i solved it, i don't have a lot of javascript knowledge but it was a simple as calling the function, but within script tags.

@if(TempData["check"] != null){

<script>doSomething()</script>}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.