-1

I would like to call a jquery function in razor, but i can't do it, why?

ClientScript.RegisterStartupScript(Page, GetType(), "success", "alert("");", true);

It says that it's not defined...

4

1 Answer 1

0

ClientScript.RegisterStartupScript() is for web forms. If you want to call a JavaScript function in a Razor template, embed the call in the template.

There are many different ways to accomplish this. In this example, the view model contains a flag that is used to conditionally output a block of script to the client.

@model MyModel

<div>
    Some code in the view...doesn't matter
</div>

@if( MyModel.ShowSuccessAlert ){
    <script>
        alert("Success!");
    </script>
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.