【问题标题】:navigate and post data from silverlight从 silverlight 导航和发布数据
【发布时间】:2012-11-09 01:07:00
【问题描述】:

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

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 方法向目标页面发送许多参数

我该怎么做?

【问题讨论】:

    标签: c# silverlight post


    【解决方案1】:

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

    要使用 POST,您可以改为使用 Silverlight 浏览器互操作以编程方式创建 HTML <form>,将其 action 属性设置为正确的 URL,将其 target 属性设置为 "_blank",添加一些 @987654327 @ 字段,设置它们的名称和值,然后submit() 表单。

    // 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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 2017-09-21
      • 1970-01-01
      • 2011-02-15
      • 2012-06-10
      • 1970-01-01
      相关资源
      最近更新 更多