-1

Want make call to javascript function from switch case statment in asp.net mvc:

@select Case imageExistOrNot(this)
   Case True
      @<a onclick="showCardImage(this)">Show</a>
   Case False
      @<a>No Image</a>
End Select

And have test JS method:

function imageExistOrNot()  
{
    return false;
}
6
  • You are calling a client method named showCardImage but the only js method you have in your question is named imageExistOrNot. Also you pass in 1 parameter but the method defined takes 0 parameters.... Is there something you are not showing or included by mistake?? Commented Jan 31, 2017 at 12:57
  • I have no knowledge of VB.NET, but I have the feeling your @select Case is executed on server-side. If that's the case, then what you are asking is not possible and does not make sense at all. Commented Jan 31, 2017 at 12:57
  • @Igor see @select Case imageExistOrNot Commented Jan 31, 2017 at 12:58
  • @CamiloTerevinto - ah. Ok, then its simple, you cant call client side script during server side rendering of the view. Commented Jan 31, 2017 at 12:58
  • I need to call controller method that return true/false, instead of js function? Commented Jan 31, 2017 at 13:01

1 Answer 1

0

ASP.NET MVC => runs at server
Javascript => runs at client, once server finished processing

You are expecting the server to know the result of a client function, which is not possible.

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

3 Comments

So how can i determine if image exist ot not? with controller method?
@BallonUra You need to perform the validation with Javascript and then call the server using AJAX (for example)
@BallonUra How are you using JS to determine if the image exists or not? Surely that's a server-side function anyway?

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.