MVC HtmlHelper;
1.URL ():
<%= html.actionlink ("User list", "Method", "Controller")%>
2.HtmlHelper controls
<%= Html.textbox ("username", NULL, NULL, new {placeholder= "Enter user name Here"})%>
Strongly typed conversions
1. Convert ViewData to strongly typed
<%IEnumerable<tb_ABc> list = viewdata["Data"] as Ienumerable<tb_abc>;%>
2. Modify the viewpage<dynamic> of the first line of the page to a strongly typed viewpage<mvcuserdemo.models.userinfo>. Can be directly in the page through the model adjustment
The object passed in the action.
3.MVC self-provided strongly typed conversions automatically generated views (recommended)
The bracket template is available when creating a view and selecting the mode type for creating a strongly typed view. Use strongly typed views to automatically generate pages
Strong type view of the table additions and deletions to change:
Check:
*.cs Code:
Userdbdatacontext dc = new Userdbdatacontext ();//linq
//
GET:/infouser/
Public ActionResult Index ()
{
viewdata["Data" = dc.tb_abc.asenumerable<tb_abc> ();
return View ();
}
[HttpGet]
Public ActionResult Create ()
{
return View ();
}
[HttpPost]
Public ActionResult Create (TB_ABC TB)
{
Dc.tb_ABc.InsertOnSubmit (TB);
dc. SubmitChanges ();
Return redirecttoaction ("Index");
}
[HttpGet]
Public ActionResult Edit (int? id)
{
Viewdata.model = dc.tb_ABc.Where (x = = X.sid = = ID). First ();
dc. SubmitChanges ();
return View ();
}
[HttpPost]
Public ActionResult Edit (TB_ABC TB)
{
var reulst = from u in DC.TB_ABC
where U.sid = = tb. Sid
Select U;
foreach (var item in Reulst)
{
Item.sname = Tb.sname;
Item. area_id = tb. area_id;
}
dc. SubmitChanges ();
Return redirecttoaction ("Index");
}
Public ActionResult Delete (int? ID)
{
Dc.tb_ABc.DeleteOnSubmit (dc.tb_ABc.Where (x = X.sid = = Id). First ());
dc. SubmitChanges ();
Return redirecttoaction ("Index");
}
------
*.aspx Code:
<%@ Import namespace= "mvcdeom.models"%>//Add Reference
<%IEnumerable<tb_ABc> list = viewdata["Data"] as Ienumerable<tb_abc>;%>
<div>
<table class= "Auto-style1" >
<tr>
<td> numbering </td>
<td> Users </td>
<td> Password </td>
<td> Details </td>
<td> Delete </td>
</tr>
<%foreach (var item in list)
{
%>
<tr>
<td><%= Html.ActionLink (item. Sid.tostring (), "Edit", "Infouser", new {
Id=item. Sid},null)%></td>
<td><%= Item.sname%></td>
<td><%= item. area_id%></td>
<td><%= html.actionlink ("Verbose", "Detail", new {Id = Item). Sid})%></td>
<td><%= Html.ActionLink ("Remove", "delete", new {Id = Item). Sid})%></td>
</tr>
<%
}
%>
</table>
HtmlHelper and strongly typed conversions