1

I am getting a missing ) after argument list in the chrome console. I don't understand why because it doesn't seem like there's missing one. I know it's not because of the string I'm passing because the string actually show how it's supposed to. so here's my code :

This is the HTML code:

<button class="btn btn-primary btn-lg" type="button" onclick="annuler(@ViewBag.id_dcr,@ViewBag.number)">
        Annuler 
</button>

This is the Javascript function :

function annuler(id_dcr, number) 
{
    window.location.href = ("/ModifyDocument/Index?id_dcr=" + id_dcr + "&number=" + number);
}

This is the C# method that pass the informations :

public ActionResult Create(int? id_dcr, int? id_user, string number)
{
    ViewBag.Documents = dbd.documents.Where(i => i.number == number).ToList();
    ViewBag.id_dcr = id_dcr;
    ViewBag.number = number;
    return View();
}

This is the C# method definition that'll be call in the JavaScript function:

public ActionResult Index(int? id_dcr, string number)
3
  • 3
    In annuler(@ViewBag.id_dcr,@ViewBag.number) if the values are string, they need to be wrapped in quotes. Commented Feb 15, 2016 at 15:53
  • what happen if you just put hard-coded values (e.g : onclick="annuler('id', 3);" ? Commented Feb 15, 2016 at 15:54
  • 3
    Look at the rendered output and check what’s wrong there. Commented Feb 15, 2016 at 15:54

1 Answer 1

1

This should fix it:

   <button class="btn btn-primary btn-lg" type="button" onclick="annuler('@ViewBag.id_dcr','@ViewBag.number')">
            Annuler 
    </button>
Sign up to request clarification or add additional context in comments.

1 Comment

ViewBag.number is a string, so it could technically contain a ' character, or even worse, a " character (leading to invalid markup).

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.