Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigate and post data from silverlight

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

and send many parameters with post method to target page

how i can do this?

like image 452
Masoomian Avatar asked Feb 07 '12 12:02

Masoomian


1 Answers

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.

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");
like image 170
Anders Marzi Tornblad Avatar answered Oct 15 '22 05:10

Anders Marzi Tornblad