My ASP. MVC2 Learning Notes < data display for a >:index page

Source: Internet
Author: User

has been doing WinForm desktop application development, so the MVC is also the understanding of these days.

The traditional three layer is the architecture, MVC is the presentation mode, MVC is equivalent to the UI layer, but the UI layer is decomposed again.

I am using a traditional three-tier architecture +MVC2 to do an example of additions and deletions. One of the traditional three-storey for convenience (lazy), the BLL of the layer has been removed. See the following items in the directory structure diagram:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/A4/wKioL1YDUbeDGR7AAAC5o1Jklfw357.jpg "title=" Aaa.png "alt=" Wkiol1ydubedgr7aaac5o1jklfw357.jpg "/>


Simple said inside to use several files: DAL, DATAACC, model these are generated by the code generator, controllers controller, Views view page. In this project, the traditional three-layer m and the M in MVC, I merge together into the traditional three-layer m.

After the introduction of the file, and then the call relationship between the several files views->controllers->dal->DATAACC-a database which I understand the model in this is a data carrier, so did not put in the relationship inside, where need to tune.

Disclaimer: The page shown below does not do any landscaping, just look at the results of the show.

Let's start by pasting the code:

Home is the initialization page in the controller index

public class Empinfocontroller:controller

{


WLsys.DAL.Fm_EmpInfo dalemp = new WLsys.DAL.Fm_EmpInfo ();

WLsys.Model.Fm_EmpInfo mdlemp = new WLsys.Model.Fm_EmpInfo ();

Public ActionResult Index ()

{

Get the information to display

List < WLsys.Model.Fm_EmpInfo > Data= dalemp. Getmodel ();

return View (data);

}

then select Index () right-click, pop Up the menu to add the view, click Add View, like configure

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/AA/wKiom1YDhaywYmSYAAFI0dhAZtg983.jpg "title=" Bbb.png "alt=" Wkiom1ydhaywymsyaafi0dhaztg983.jpg "/>

Click Add to generate index.aspx in the Views folder

In Index.aspx, replace the first line with the following:

<%@ page language= "C #" inherits= "system.web.mvc.viewpage<ienumerable<wlsys.model.fm_empinfo>>"% >

The development environment can be run to see the following effects.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/A7/wKioL1YDhu-zIeyGAAHNBMgPwkA567.jpg "title=" cc.png "alt=" Wkiol1ydhu-zieygaahnbmgpwka567.jpg "/>


The ability to include "new", "edit", "delete", "detail" in this page is detailed in the following sections


Finally, post the code in the Getmodel () method in the Dal:

<summary>

Get an Object entity

</summary>

Public list<wlsys.model.fm_empinfo> Getmodel ()

{

StringBuilder strSQL = new StringBuilder ();

Strsql.append ("select");

Strsql.append ("Id,deptnum,empname,empspell,empsex,empduty,empbirth,birthnote,emptel,empemail,empaddress, Empeduc,empnation,empcard,empsalary,empmark,opid,opt,epmphoto,datain ");

Strsql.append ("from Fm_empinfo");

SqlDataReader SDR = Dbhelpersql.executereader (strsql.tostring ());

list<wlsys.model.fm_empinfo> empinfo = new list<wlsys.model.fm_empinfo> ();

Try

{

while (SDR. Read ())

{

WLsys.Model.Fm_EmpInfo fem = new WLsys.Model.Fm_EmpInfo ();

Fem. Birthnote = sdr["Birthnote"]. ToString ();

Fem. DataIn = sdr["DataIn"]. ToString ();

Fem. Deptnum = sdr["Deptnum"]. ToString ();

Fem. empaddress = sdr["Empaddress"]. ToString ();

Fem. Empbirth = sdr["Empbirth"]. ToString ();

Fem. Empcard = sdr["Empcard"]. ToString ();

Fem. Empduty = sdr["Empduty"]. ToString ();

Fem. Empeduc = sdr["Empeduc"]. ToString ();

Fem. Empemail = sdr["Empemail"]. ToString ();

Fem. Empmark = sdr["Empmark"]. ToString ();

Fem. EmpName = sdr["EmpName"]. ToString ();

Fem. Empnation = sdr["Empnation"]. ToString ();

Fem. empsalary = Decimal. Parse (sdr["Empsalary"). ToString ());

Fem. Empsex = sdr["Empsex"]. ToString ();

Fem. Empspell = sdr["Empspell"]. ToString ();

Fem. Emptel = sdr["Emptel"]. ToString ();

Fem. Epmphoto = sdr["Epmphoto"]. ToString ();

Fem.id =int. Parse (sdr["ID"). ToString ());

Empinfo. ADD (FEM);

}

Sdr. Close ();

return empinfo;

}

Finally

{

Sdr. Close ();

}

}









This article is from the "one Leaf Isolated City" blog, please be sure to keep this source http://xinyuan178.blog.51cto.com/3370338/1697801

My ASP. MVC2 Learning Notes < data display for a >:index page

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.