我想文本框的值,控制器如何從視圖中Asp.NET MVC傳遞數據
我用Ajax.ActionLink("Search","Result",new{id="**VALUE**"}, new AjaxOptions{...})
@* This is the Index.cshtml *@
<input id="cityName" type="text" class="form-control" placeholder="Enter a CityName">
@Ajax.ActionLink("Search", "Result", new { id = "I want to get the cityName" }, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "cityInfo", LoadingElementId = "loading" }, new { @class = "btn btn-default" })
<div id="cityInfo"> @When I click the actionlink , the controller will return a partialview
@Html.Partial("Result", Model)
</div>
@*This is the Result.cshtml*@
<p>
@if (@Model!=null)
{
@Model.cityInfo
}
</p>
這是index.cshtml - >> enter image description here
感謝
public PartialViewResult Result(string cityName)//this is the controller
{
CityModel city = new CityModel(cityName);
city.getInfo();
return PartialView("Index",city);
}
您的代碼需要在這個問題(沒有鏈接到它的圖像)。你不能 - 你需要一個表單來提交你的文本框的值(或者一些javascript) –
@StephenMuecke你能告訴我如何編寫javascript,請 – Suen
你需要**編輯你的問題**來解釋更多關於你想在這裏做什麼(我最好的猜測是你想要某種'搜索'文本框,然後你點擊'搜索'按鈕,你想使用ajax來顯示基於文本框?) –