[英]ASP.NET MVC 2 Data Collection on Site.Master Page
I have a site.master page in which I need to collect a newsletter signup, so I would prefer if I can provide feedback immediately to the user as they signup, and not disrupt any other page activities. 我有一个site.master页面,我需要在其中收集新闻简报注册,因此,如果我可以在用户注册时立即向用户提供反馈,并且不中断任何其他页面活动,则希望这样做。 It is a simple textbox and button.
这是一个简单的文本框和按钮。
The data then gets written to a remote WCF web service, so could I use an AJAX call, although that would be cross domain, which might be an issue. 然后将数据写入远程WCF Web服务,因此我可以使用AJAX调用,尽管那将是跨域的,这可能是一个问题。 The service returns a message of success or why failed.
该服务返回成功或失败原因的消息。
So, my questions are, what would be the best approach for this implementation, and can I use the service? 因此,我的问题是,什么是实现此方案的最佳方法,我可以使用该服务吗?
Thanks! 谢谢! Brad
布拉德
In order to avoid the cross-domain problem, I would use the "double hop" solution. 为了避免跨域问题,我将使用“双跳”解决方案。 First, add a reference to the WCF service in your project.
首先,在您的项目中添加对WCF服务的引用。 Then create a method in your Controller that returns a
JsonResult
, and inside that method you can call the WCF service and return the result as JSON. 然后在Controller中创建一个返回
JsonResult
方法,然后在该方法内调用WCF服务并将结果作为JSON返回。
Then in the client app you can use a standard .ajax()
method to do the sign-up. 然后,在客户端应用程序中,您可以使用标准的
.ajax()
方法进行注册。 It's a little convoluted with the number of hops, but it lets you control each step of the process and avoids the cross-domain problem. 它与跃点数有些混淆,但是它使您可以控制过程的每个步骤,并避免了跨域问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.