ActionLink 出现问题
我想知道是否有办法做类似网络表单之类的事情..或者一个很好的方法来做到这一点.. 我的“索引”视图上有一个 ActionLink("foo", "fooAction") 。在此 fooAction 中,我调用一个返回“True”或“False”的方法,根据返回值,我必须向用户提供一些反馈,并返回具有相同结果 + 反馈的“Index”。
在网络表单中,我们只需在方法上设置“label.visible = true; | label.text = 'bla'”或w/e。
我说清楚了吗? 谢谢 !
编辑:
我会使用网络表单来更好地解释一些伪代码:
<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 的情况下做到这一点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的操作不能只返回“有效”或“无效”文本吗?
所以你可以像
编辑
一样对你的操作进行操作
Can't you action just return the "worked" or "didn't work" text ?
So you can do like
Edit
On your action
它通常通过 Post - Redirect -Get 完成。
您发布到更改某些数据的操作。该 dataobjects 属性将设置为 yes 或 false。
然后,您重定向到显示数据(索引)的操作。
如果是/否更多的是关于操作是否成功,那么您通常会在重定向到索引之前将结果放入 tempdata 中。
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.
您可以通过 jQuery $.ajax 请求调用该操作。启动此操作后,您可以返回带有反馈的 json 结果,并使用 jQuery 将其加载到 dom 中。有关类似内容的示例单击此处。
希望它有帮助,如果需要扩展,请告诉我:-)
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 :-)