mvc html 文本,ASP.NET MVC获取文本框输入值_html_开发99编程知识库

標記包裝所有輸入。 你可以使用HTML標記或者 ASP.NET MVC helper @Html.BeginForm(...) 來完成它。 提交表單后,所有輸入數據都將發送到控制器操作。 請參見一個示例:

視圖:@using (Html.BeginForm("Search","Events"))

{

@Html.TextBox("name")

}

控制器:public class EventsController: Controller

{

public ActionResult Search(string name)

{

//do something

return View();//return"Search" view to the user

}

}

如果你需要使用更複雜的類型,只需lern如何在 ASP.NET MVC中使用模型。 下面是一個簡單的示例:

模型( C# ):public class UserModel

{

public string FirstName { get; set; }

public string LastName { get; set; }

}

視圖:@model UserModel

@using (Html.BeginForm("Search","Events"))

{

@Html.TextBoxFor(m => m.FirstName)

@Html.TextBoxFor(m => m.LastName)

}

控制器:public class EventsController: Controller

{

public ActionResult Search(UserModel model)

{

//do something

return View();//return"Search" view to the user

//return View(model);//You can also return view with the model to the user

//return View("SpecificView");//You can specify a concrete view name as well

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值