2010-04-19 93 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

希望它有幫助,讓我知道如果這需要擴大:-)