0

I have this button code in ASP.NET MVC 5.

In the browser I get this error :

Uncaught SyntaxError: Unexpected string

<input type="button" value="Bid for this project" 
       onclick="location.href'@Url.Action("Create", "Bid", new {projectid = Model.ProjectID})'" />

In browser, button looks like this :

<input type="button" value="Bid for this project" 
       onclick="location.href'/Bid/Create?projectid=1'" />

Can you tell me how to make this right? Thanks.

3 Answers 3

2

The string is missing the assignment operator = after the href:

<input type="button" value="Bid for this project" 
 onclick="location.href='@Url.Action("Create", "Bid", new {projectid = Model.ProjectID})'" />

In browser:

<input type="button" value="Bid for this project" onclick="location.href='/Bid/Create?projectid=1'" />

It should work after you add it.

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

Comments

2

You are missing an = sign

<input type="button" value="Bid for this project" onclick="location.href='@Url.Action("Create", "Bid", new {projectid = Model.ProjectID})'" />

Comments

2

You missed = after href

<input type="button" value="Bid for this project" onclick="location.href= '@Url.Action("Create", "Bid", new {projectid = Model.ProjectID})'" />

As the correct javascript syntax is

location.href= '@Url.Action("Create", "Bid", new {projectid = Model.ProjectID})';

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.