Daniel
Daniel

Reputation: 2948

Trouble with ActionLink

I wanna know if there's a way to do something like webforms .. Or a nice way to do this .. I have an ActionLink("foo", "fooAction") on my "Index" view. In this fooAction, I call a method that returns "True" or "False" and depending on the return, I have to give to the user, some feedback and return the "Index" with the same results + the feedback.

In webforms we would just set "label.visible = true; | label.text = 'bla'" or w/e on the method.

Am I clear ? Thanks !

Edit:

Some pseudocode I would do using webforms to explain better:

<asp:button OnCommand="method1">
  - Method1(){
    var response = ws.MethodFromWebService(); //call a method from the Web Service and get the return(true/false)
    if (response)
       feedbackLabel.Text = "worked";
    else
       feedbackLabel.Text = "didn't work";
    feedbackLabel.Visible = true;
    }

I'd like to do that without javascript.

Upvotes: 0

Views: 227

Answers (3)

WestDiscGolf
WestDiscGolf

Reputation: 4108

You could call the action via a jQuery $.ajax request. Once you have initiated this you can return a json result with the feedback and load it into the dom using jQuery. For an example of something similar click here.

Hope it helps, let me know if this needs expanding on :-)

Upvotes: 0

Mathias F
Mathias F

Reputation: 15891

Its usually done via Post - Redirect -Get.

You post to an Action that changes some data. This dataobjects property would be set to yes or false.

You then redirect to an Action that displays the data (index).

If yes / no is more about if an action suuceeded or not , then you would usually put the result into tempdata before redirecting to index.

Upvotes: 0

Rafael Mueller
Rafael Mueller

Reputation: 6083

Can't you action just return the "worked" or "didn't work" text ?

So you can do like

$.get("Foo/FooAction", function(html){
    $("#feedbackLabel").show().html(html);

});

Edit

On your action

public ContentResult FooAction(){
    if(SomeThing())
        return "worked";
    else
        return "didnt worked";
}

Upvotes: 1

Related Questions