I am able to post the data from Excel to ASP.NET MVC web service. Here is My code for that:
Sub SendData()
Dim HttpReq As Object, url As String
Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP"开发者_高级运维)
url = "http://localhost:11121/Student/PostData/"
HttpReq.Open "POST", url, False
HttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HttpReq.Send "Student=jsmith112"
Debug.Print HttpReq.ResponseText
End Sub
Now, I Want to have a ControllerAction "Insert" That will Insert this posted data in SQLServer Database.
What do I need to do to controller action for this?
You need to add <AcceptVerbs(HttpVerbs.POST)
> attribute if it's vs2008 or just <HttpPost()>
for vs2010 to your controller method, so it receives the posted data.
Please note that this is in C#, syntax is slightly different for VB.
精彩评论