开发者

Trouble with ActionLink

开发者 https://www.devze.com 2022-12-27 04:26 出处:网络
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 r

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" o开发者_高级运维r "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.


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";
}


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.


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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消