从 Silverlight 导航和发布数据 [英] navigate and post data from silverlight

查看:23
本文介绍了从 Silverlight 导航和发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是silverlight导航项目(IN-Browser)我想导航到一个 URL,例如:

My project is silverlight navighation project (IN-Browser) I want to navigate to an Url such as :

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(string.Format("http://{0}:
{1}/ReportProject.aspx#/Supplies/RequestGoods/RequestGoodsDashboard", 
Application.Current.Host.Source.Host, 
Application.Current.Host.Source.Port)), "_blank", "");

并使用post方法将许多参数发送到目标页面

and send many parameters with post method to target page

我该怎么做?

推荐答案

您不能 Navigate() 并且仍然使用 POST.Navigate 相当于单击链接或在地址栏中键入 URL,这会调用 GET 动词.

You cannot Navigate() and still use POST. Navigate is the equivalent of clicking a link or typing a URL in the address bar, which invokes the GET verb.

要使用 POST,您可以改为使用 Silverlight 浏览器互操作以编程方式创建 HTML

,将其 action 属性设置为正确的 URL,将其设置为target 属性给 "_blank",添加一些 <input type="hidden"> 字段,设置它们的名称和值,然后 <代码>提交()表单.

To use POST, you could instead use the Silverlight browser interop to programmatically create an HTML <form>, set its action attribute to the correct URL, set its target attribute to "_blank", add some <input type="hidden"> fields, set their names and values and then submit() the form.

// Get document and body
var doc = System.Windows.Browser.HtmlPage.Document;
var body = doc.Body;

// Create a <form> element and add it to the body
var newForm = doc.CreateElement("form");
newForm.SetAttribute("action", targetUrl);
newForm.SetAttribute("method", "post");
body.AppendChild(newForm);

// TODO: doc.CreateElement("input");
// TODO: SetAttribute("type", "hidden");
// TODO: SetAttribute("name", someName);
// TODO: SetAttribute("value", someValue);
// TODO: newForm.AppendChild()

newForm.Invoke("submit");

这篇关于从 Silverlight 导航和发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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