Nopcommerce 3.80 Framework Study (ii) MVC presentation layer and data validation

Source: Internet
Author: User
Tags nopcommerce

Presentation layer Frame Structure/views/shared/_root.head.cshtml/views/shared/_root.cshtml/views/shared/_columnsone.cshtml/views/_ Viewstart.cshtml
    1. Outermost:/views/shared/_root.head.cshtml root frame
    2. /views/shared/_root.cshtml contains the mall Web page header and navigation menu, which contains:
      1. @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
        1. @Html. Action ("Logo", "Common") is located on/common/logo.cshtml Web page header site name and other content
        2. @Html. Action ("Headerlinks", "Common") User login information, Favorites and other content
        3. @Html. Action ("Flyoutshoppingcart", "ShoppingCart") Shopping cart
        4. @Html. Action ("SearchBox", "Catalog") search box
      2. @Html. Action ("Footer", "Common") site bottom Content
    3. /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
    4. /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

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.