0

我想知道是否有办法做类似 webforms 的事情 .. 或者一个很好的方法来做到这一点 .. 我的“索引”视图上有一个 ActionLink("foo", "fooAction")。在这个 fooAction 中,我调用了一个返回“True”或“False”的方法,根据返回,我必须给用户一些反馈,并返回具有相同结果的“索引”+反馈。

在网络表单中,我们只需在方法上设置“label.visible = true; | label.text = 'bla'”或 w/e。

我清楚了吗?谢谢 !

编辑:

一些伪代码我会使用 webforms 来更好地解释:

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

我想在没有 javascript 的情况下做到这一点。

4

3 回答 3

1

你不能行动只返回“工作”或“没有工作”的文字吗?

所以你可以这样做

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

});

编辑

关于你的行动

public ContentResult FooAction(){
    if(SomeThing())
        return "worked";
    else
        return "didnt worked";
}
于 2010-04-19T17:04:54.780 回答
0

它通常通过 Post - Redirect -Get 完成。

您发布到更改某些数据的操作。此 dataobjects 属性将设置为 yes 或 false。

然后,您重定向到显示数据(索引)的操作。

如果 yes / no 更多的是关于动作是否成功,那么您通常会在重定向到 index.html 之前将结果放入 tempdata 中。

于 2010-04-20T08:36:03.323 回答
0

您可以通过 jQuery $.ajax 请求调用该操作。启动此操作后,您可以返回带有反馈的 json 结果并使用 jQuery 将其加载到 dom 中。有关类似内容的示例,请单击此处

希望它有所帮助,让我知道这是否需要扩展:-)

于 2010-04-20T08:43:24.913 回答