Reputation: 1745
Maybe I ask simple question, but I have it :)
I have one site(call it SenderSite) and post receiver site(call it ReceiverSite). They hosted is different host servers in internet. SenderSite has written in asp.net and ReceiverSite has written in asp.net mvc.
I open SenderSite in browser. I have form with data and textbox where I can write url site that take response (for example, www.example.com/TestMethod). When I click send, request will send to reseiver site. How mvc method should look like to receive post data.
I write it like:
[HttpPost]
public void TestMethod()
{
}
Should I write some parameters for this method? When I'll take it, can i write it in a page?
Thanks!
Upvotes: 1
Views: 2079
Reputation: 33305
You could create an object i.e. SentModel
, then make sure that the Name fields from the sending site match the properties within the object.
As an example:
public class SentModel
{
public string Input1 { get; set; }
public string Intput2 { get; set; }
}
[HttpPost]
public void TestMethod(SendModel model)
{
model.Input1.ToString();
}
Then in your aspx page:
<form method="post" action="http://www.example.com/Controller/TestMethod" id="form1">
<div>
<asp:textbox runat="server" id="Input1" ClientIDMode="Static" />
<asp:textbox runat="server" id="Intput2" ClientIDMode="Static" />
<input type="submit" value="submit" />
</div>
</form>
As you can't set the Name property to be the Id easily you will also need to use some jQuery to rename the fields as a workaround:
$.each($('div').children(), function() {
$(this).attr("name",$(this).attr("id"));
});
The above has the benefit of a strongly typed object which you can pull properties from. You can also add data annotations to the object to control validation coming into your action.
Another option is to include the form name parameters in the controller action:
[HttpPost]
public void TestMethod(string Input1, string Input2)
{
Input1.ToString();
}
This has the downsides of adding all the parameters to the method, if a property is added/removed your method needs to change.
The last option is just to pull it from the request as Request.Form["Input1"]
.
Upvotes: 3