Presentation layer Frame Structure/views/shared/_root.head.cshtml/views/shared/_root.cshtml/views/shared/_columnsone.cshtml/views/_ Viewstart.cshtml
- Outermost:/views/shared/_root.head.cshtml root frame
- /views/shared/_root.cshtml contains the mall Web page header and navigation menu, which contains:
- @Html. Partial ("Header") part of the page is located in the header.cshtml of the/shared sibling directory, the Html.partial method draws a page that does not have a corresponding controller, contains the main number of pages in the header of the action
- @Html. Action ("Logo", "Common") is located on/common/logo.cshtml Web page header site name and other content
- @Html. Action ("Headerlinks", "Common") User login information, Favorites and other content
- @Html. Action ("Flyoutshoppingcart", "ShoppingCart") Shopping cart
- @Html. Action ("SearchBox", "Catalog") search box
- @Html. Action ("Footer", "Common") site bottom Content
- /views/shared/_columnsone.cshtml main layout page, the content of the Web page is not included in the same directory as the sidebar and there is a _columnstwo.cshtml with sidebar
- /views/_viewstart.cshtml All MVC View pages use this template by default
All content in the Views folder except _viewstart.cshtml can be/themes/the current theme name/views directory corresponding to the same name as the file substitution
Background theme Settings feature link/admin/setting/generalcommon
form data validation
Take the ~/views/customer/info.cshtml page as an example
Login and click on the user name home
Nop.Web.Controllers.Action definition
[Nophttpsrequirement (Sslrequirement.yes)] PublicActionResult Info () {if(!_workcontext.currentcustomer.isregistered ())return NewHttpunauthorizedresult (); varCustomer =_workcontext.currentcustomer; varModel =NewCustomerinfomodel (); Preparecustomerinfomodel (model, customer,false); returnView (model); }
The Action return type is Nop.Web.Models.Customer.CustomerInfoModel can be selected type Press shortcut key F12 Open File view type definition
The Customerinfomodel type definition. The customerinfovalidator of the head is the type rule validation definition
[Validator (typeof(Customerinfovalidator))] Public Partial class Customerinfomodel:basenopmodel
In the constructor, you can use a chain expression like jquery for rule validation
Rulefor (X=>x.email). Notempty (). Withmessage ("Cannot be empty"). When (x=>x.email>). Withmessage ("Content too Long")
property validation, where nopresourcedisplayname can be replaced with System.ComponentModel.DisplayName if no internationalization is required
attribute value can be replaced by Chinese name
[Nopresourcedisplayname ("Account.Fields.Username")] [allowhtml] Public string Get set; }
form definition:
<div class= "Page-body" >
@using (Html.BeginForm ())
{
<!--form definition--
}
The using (Html.BeginForm ()) is submitted by default to the current action with the same name, i.e.
Public ActionResult Info (Customerinfomodel model, formcollection form)
You can also define the action name you point to
using (Html.BeginForm ("ActionName", "Controllername", new {other parameter name = other parameter value}))
Some of the MVC grammar summaries
About Html.action and html.partial
Partial and RenderPartial:
Both of the properties are the same, only refers to a view to the inlay in, but the return value is a little different
An object (mvchtmlstring) that returns a string to return a bunch of HTML, and then writes it to the main page.
@Html. Partial ("ViewName")
The renderpartial callback is void, and this method adds the specified view to the main page
@{html.renderpartial ("ViewName");}
These two methods do not use the controller, is to directly put a view (Page) to add in
and renderaction a bit different, this is an action, so will use the controller and then return a page
Detailed reference: Html.partial, renderpartial, action,renderaction Differences and usage in ASP.
Spit it out. While Windows Live Writer can insert code highlighting, the highlighted format is less satisfying than the previous one, which was published in Word, and you can paste the code style in VS directly
Preview Next: Dynamic routing in Nopcommerce 3.80
Nopcommerce 3.80 Framework Study (ii) MVC presentation layer and data validation