views:

146

answers:

4

Basically, i don't want to use <input type="submit"> mainly because it's a button, i'd rather user ActionLink, so i am using Ajax.ActionLink, and i'm not sure what to place in the routeValues argument for it to pickup the new (edited) data (user enters comments etc) and send it to my action. would any of you know? thanks.

this is what i have, but of course, it sends the original comment before user edit back to the server/action :)

<%= Ajax.ActionLink("Update", "UpdateComment", Model.Comment,
      New AjaxOptions With
      {.UpdateTargetId = Model.CommentDivId, .HttpMethod = "Post"})%>

ps: i know how to do this in javascript, and doing ajax posts etc, hope to find and mvc only solution

A: 

If it's only the button you're worried about then why not apply a bit of css to change the button into a link? No one will know the diff and you'll save yourself a bit of work.

If this is not what you're after then let me know and I can remove this answer.

As for Ajax, I'm not sure you're model will be updated as it should be out of scope. I think the way to do this is to pass all your data across as variables. Not an ideal solution really.

I'd use the css approach on this one.

edit

<head>
    <style>
        .buttonAsLink{ background-color:white; border:0; color:Blue; text-decoration:underline;}
        .buttonAsLink:hover{ text-decoration:none;}
    </style>
</head>
<body>
    <input class="buttonAsLink" type=submit value="Click Me" />
</body>
griegs
i've tried this css approach and it doesn't act like a button, no underline during hover-over etc... unless there is a fool proof css button styling that makes it act exactly like a normal link? if so i would love to see it.
Erx_VB.NExT.Coder
also, why would it be out of scope when using ajax?
Erx_VB.NExT.Coder
my understanding is that when you do an ajax call it's like a web method and not a normal post to an action. as for the css, let me play for a couple of minutes.
griegs
just about to try it, but how about "background-color:transparent;" instead? also, i think the text-decoration attribs could be in the wrong place... swap around? either way, i tried it, and the hover effect is nto working.
Erx_VB.NExT.Coder
erm, might work yeah? :) I just tried the first thing that came to mind as i figured getting it to look right was the priority.
griegs
i tried it with the corrected hover thingy, and its still not working... when you hover over, the underline does not come up.
Erx_VB.NExT.Coder
Hmm, this might be a browser thing. It works for me in FF and IE7 no probs. if that's the case then you can't use this and you might need to pass in the values you want via variables in your ajax post.
griegs
and re ur model binding mention, will create another post to get to the bottom of that, as it doesn't seem to be binding and google mentions nothing.
Erx_VB.NExT.Coder
A: 

How about just making an ajax call with jQuery on click of your html link? Something like this or this.

thekaido
i was thinking about doing this, however was hoping for an in uilt mvc model binder to do the work via an ActionLink...
Erx_VB.NExT.Coder
You build something similar to the ActionLink to build the jQuery call
thekaido
A: 

I would recommend you still wrap the comment field with form and submit the fields with an anchor and some javascript.The generated html looks like...

<form id="the_form">
  <textarea id="comment"></textarea>
  <a href="javascript:{}" onclick="document.getElementById('the_form').submit(); return   false;">submit</a>
</form>

You can easily replace this with the HtmlHelper in MVC or some other ViewEngine code, but the point is to submit the form with the link (anchor tag) and the parameters will get mapped to the action method.

Hope that helps,

Eddy

PS. You could also use the Ajax.BeginForm to achieve the same.

Dax70
+1  A: 

Basically, you can not do this alone in an ActionLink and MVC, you need to use JavaScript to achieve what you are after! If you want to use JavaScript, there are examples above you can choose from!

I do wish therewas a HTML helper so we didn't need to do messy jquery mashups to access real-time form data, but there isn't, perhaps someone can create a helper and share it with us?