0
這是我的控制器如何從控制器(Content.ReadAsAsync)通過參數API控制器mvc4
public ActionResult Index(string Searchby, string SearchValue)
{
var client = new HttpClient();
var productDetailUrl = Url.RouteUrl(
"DefaultApi",
new { httproute = "", controller = "Assets" },
Request.Url.Scheme
);
var model = client
.GetAsync(productDetailUrl)
.Result
.Content.ReadAsAsync<AssetDetails[]>().Result;
return View(model);}
searchby和searchvalue PARAMS來了形式
<script type="text/javascript">
$(function() {
$('#txtSearch').blur(function() {
var Searchby = $('select[name="Searchby"]').val();
var SearchValue = $("txtSearch").val();
$.ajax({
type: "POST",
url: '/Asset/Index',
data: { Searchby: searchby, SearchValue: SearchValue },
})
});
});
我應該如何通過Searchby,來自ReadAsAsync的SearchValue
我在webapiconfig config.Routes.MapHttpRoute將此添加( 名: 「DefaultApi」, routeTemplate: 「API/{控制器}/{Searchby}/{SearchValue}」 ); – Karthik