如何在MVC4中将数据从控制器传递到视图? [英] How to pass data from controller to view in MVC4?

查看:114
本文介绍了如何在MVC4中将数据从控制器传递到视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要将数据从控制器传递到视图。在我的页面中有多个图像和按钮。每个图像都有一个按钮,每个图像都有4个数据字段



如字段1:数据,

字段2:数据,

等...



如果我点击按钮我需要将该信息发送到另一页。它会怎么做?请帮助我。





谢谢

krishna

Hi All, I need to pass data from controller to view. In my page multiple images and button's are there. Every image have one button, and every image have 4 fields of data

like field 1 : data,
field 2: data,
etc...

If i click button i need to send that information to another page. How it will do that? Please help me on that.


Thanks
krishna

推荐答案

为每个图像和按钮创建多个局部视图,您可以将按钮放在局部视图中或只在索引/主页上设置。使用ajax帖子,您可以和@ html.renderparcial一起在另一个页面上按钮调用它点击功能使用javascript方法

https://www.youtube.com/watch?v=SABg7RyjX-4

以上视频将显示你究竟如何使用partial观点



https://www.youtube.com/watch?v=GrycH6F-ksY

第二个视频将告诉你如何使用表格并用ajax发布



一旦你弄清楚所有你需要做的就是创建javascript方法来调用onclick函数

javascript onclick函数(请注意调用一个按钮你需要参考按钮id才能使onclick工作),然后每个方法如果4个按钮ul有4个方法将使用ajax post将parcial视图重定向到新页面
Create multiple partial views for each image and button you can place the button in the partial view or just set it on you index/home page .Using ajax post you can and @html.renderparcial you can then call it on another page on button click function using a javascript method
https://www.youtube.com/watch?v=SABg7RyjX-4
the above video will show u exactly how to use partial views

https://www.youtube.com/watch?v=GrycH6F-ksY
the second video will show u how to use forms and post with ajax

once you’ve got that figured out all you have to do is create javascript methods to call the onclick functions
javascript onclick functions (please note calling a button u need to refer to the button id for the onclick to work),then each method if 4 buttons ul have 4 methods that will use ajax post to redirect the parcial view to a new page


这篇关于如何在MVC4中将数据从控制器传递到视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆