tags:

views:

23

answers:

1

So this seems like it should be simple. I'd like to set a public model property from javascript that's fired on the mouseover of an image.

So something like this:

Html:

...img src="<%=Model.AppDetails.Logo%>" onmouseover="showMenu(this);...

Javascript:

function showMenu(app) {
<%Model.CurrentId = app.id%> //app.id is of course undefined here
...

Or is a better approach to call a controller method to set it? If so what's the best approach? Ajax? Seems like a lot of heavy lifting for something so simple.

Appreciate the feedback.

Sharon

A: 

What exactly are you trying to do with Model.CurrentId? If you're trying to just send it back to the server when the page next sends information, use a hidden field or similar.

However, if you're trying to set a value on the server when the user mouses over an image, of course you need to use ajax or similar. How else is the server going to know what the client is doing.

If you want to use Model.CurrentId later in the same file, you will need to re-apply the template as well. Once the view is processed on the server, the client has no information from the template (the client doesn't see the <%...%> tags, those are replaced on the server before sending).

I can't imagine any scenario where you'd want to send information to the server on a mouseover unless you were going to also get information back (like an extended tooltip, or an image popup), so ajax is probably your best option.

Philip Rieck
Oh, I had my misguided reasons(with emphasis on misguided). Appreciate your reply.
shershon