2010-04-19 91 views
0

我想知道是否有办法做webforms的东西..或者一个很好的方法来做到这一点.. 我有我的“索引”视图上的ActionLink(“foo”,“fooAction”)。在这个函数中,我调用一个返回“True”或“False”的方法,并且根据返回结果,我必须给用户一些反馈,并返回具有相同结果和反馈的“索引”。麻烦与动作链接

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

我清楚吗? 谢谢!

编辑:

一些伪我会做使用web表单更好地说明:

<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。

+0

有点困惑。所以你想传递一个true或false到你的Controller Action? – 2010-04-19 15:17:34

+0

是的,没有改变视图的结果.. – Daniel 2010-04-19 15:56:05

回答

1

你不能只是返回“工作”或“没有工作”的文本?

所以,你可以像

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

}); 

编辑

在你的行动

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

对不起,忘了提及我不能使用这样的JavaScript。 – Daniel 2010-04-19 20:09:21

+0

@丹尼尔为什么不呢?这是一个技术限制吗? – mxmissile 2016-07-26 18:00:56

0

它通常是通过后做 - 重定向 - 获得。

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

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

如果是/否更多关于如果行动suuceeded或没有,那么你通常会把结果放入tempdata重定向到索引。

0

您可以通过jQuery $ .ajax请求调用操作。一旦你发起了这个,你可以返回一个带有反馈的json结果,并使用jQuery将它加载到dom中。例如类似的东西click here

希望它有帮助,让我知道如果这需要扩大:-)