Controllor
------------------------public ActionResult GetResult(string name)
{
return Content("hello, " + name);
}
View
------------------------<script type="text/javascript">
function GetMessage() {
$.get("/Home/GetResult/", function (response) {
$("#mySpan").html(response);
});
}
</script><input type="text" maxlength="8" id="characterName" />
<input type="button" onclick="GetMessage()" value="开始" />
<span id="mySpan"></span>
如上,请问如何把 characterName 传递到controllor?
------------------------public ActionResult GetResult(string name)
{
return Content("hello, " + name);
}
View
------------------------<script type="text/javascript">
function GetMessage() {
$.get("/Home/GetResult/", function (response) {
$("#mySpan").html(response);
});
}
</script><input type="text" maxlength="8" id="characterName" />
<input type="button" onclick="GetMessage()" value="开始" />
<span id="mySpan"></span>
如上,请问如何把 characterName 传递到controllor?
解决方案 »
- 在server 2003系统下vs2008开发的winform程序在win7下显示不了数据咋回事???
- 问一些关于MVC的基础问题
- 如何使用table画柱形图
- treeview的结点绑定了text和value两个属性,如何在事后根据一个value值选中此结点的checkbox
- xp下装不了iis,我晕!~
- 文本操作问题,请知者帮忙
- 请各位大侠留意:我使用window.showModalDialog()打开了一个.aspx页面,希望单击按钮执行处理之后能够自动关闭该对话框?
- 谁帮帮忙啊
- 大家好,哪里有:matlab安装程序下载, 谢谢
- 微软的Microsoft.Web.UI.Web.UI.WebControl.TreeView的问题
- 数据分页,一个很奇怪的现象
- 想要把自己做的网站放到网上。。。求流程。。。
<script type="text/javascript">
function GetMessage() {
$.get("/Home/GetResult/"+$("#characterName"), function (response) {
$("#mySpan").html(response);
});
}
</script>routes.MapRoute(
"GetMessage", // 流程附件上传
"{Home}/{GetResult}/{name}", // 带有参数的 URL
new { controller = "Home", action = "GetResult", name= UrlParameter.Optional}
);public ActionResult GetResult(string name)
{
return Content("hello, " + name);
}
这样需要在路由中重新配置规则,因为默认路由传递参数为id.<script type="text/javascript">
function GetMessage() {
$.get("/Home/GetResult/?characterName="+$("#characterName"), function (response) {
$("#mySpan").html(response);
});
}
</script>public ActionResult GetResult()
{
return Content("hello, " + Request.QueryString["characterName"]);
}
hi, a1214668850
我按你的方法配置了路由,在 default 路由的下面:routes.MapRoute(
"Default", // 路由名称
"{controller}/{action}/{id}", // 带有参数的 URL
new { controller = "Account", action = "AccountIndex", id = UrlParameter.Optional } // 参数默认值
); routes.MapRoute(
"CheckExists", // 路由名称
"{controller}/{action}/{characterName}", // 带有参数的 URL
new { controller = "Account", action = "CheckExists", characterName = UrlParameter.Optional } // 参数默认值
);------------ Controllor :public ActionResult CheckExists(string characterName)
{
return Content("hello," + characterName);
}------------ View:
$.get("/Account/CheckExists/" + $("#characterName").val(), function (response) {
if (response == "true")
$("#createResult").html("名称不可用,请使用其他名称。");
else
$("#form1").submit();
});但我断点发现,传递到 Controllor 时,characterName 为 null。这是为什么呢?
alert($("#characterName").val()); // 弹出的结果是文本框输入的内容
$.get("/Account/CheckExists/" + $("#characterName").val(), function (response) {
if (response == "true")
$("#createResult").html("名称不可用,请使用其他名称。");
else
$("#form1").submit();
});