我是全新的asp.net mvc。我在使用asp.net mvc4應用程序中的其他Web服務時遇到了麻煩。在asp.net mvc 4應用程序中使用Restful WCF服務
這是服務的接口:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetRuleDetail/{id}")]
string GetRuleDetail(string id);
}
在我的MVC應用程序,我將我的服務作爲服務引用「ServiceReference1」
然後我創建了一個控制器:
public ActionResult Index()
{
string strjson = Request["Json"].ToString();
//string strjson = "input={\"name\": \"obj1\",\"x\": 11,\"y\":20,\"obj\":{\"testKey\":\"val\",},\"tab\":[1 , 2, 46]}";
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
return View(obj.GetRuleDetail(strjson));
}
字符串strjson,我想通過它從具有以下代碼的視圖:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";} <h2>Index</h2> <section class="contact">
<header>
<h3>Enter your JSON string</h3>
</header>
<p>
<ol>
<li>
@Html.Label("Json")
@Html.TextBox("txtJson")
</li>
</ol>
</p>
<p>
<button>Test</button>
</p>
我錯過了什麼嗎? Cz strjson始終爲null,並且在我在文本框中輸入jsonstring之前執行Index()方法。我該如何解決這個問題plz
什麼將文本框的價值和id然後傳遞給服務的東西? – Mairaj 2015-04-02 09:00:36
我希望用戶在文本框中輸入一個字符串,並將此字符串用作調用服務方法的id GetRuleDetail – 2015-04-02 09:03:51