我想文本框的值,控制器如何从视图中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来显示基于文本框?) –