HtmlHelper and strongly typed conversions

Source: Internet
Author: User
Tags actionlink

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.