The volleyball Scoring of MVC development (vii) Validation editing method

Source: Internet
Author: User

Modify the code to make the release releasedate look better. Open balls \ Ball.cs file

Using System;

Using System.ComponentModel.DataAnnotations;

Using System.Data.Entity;

Namespace Balls.models

{

public class ball{

public int ID {get; set;}

public string one1{get; set;}

public string One2 {get; set;}

public string one3{get; set;}

}

public class Ballsdbcontext:dbcontext

{

Public dbset<ball> Team {get; set;}

}

}
Add/balls to the browser's address bar and browse to the Balls page. And go to the edit page.

The Maproute method is to use HTTP request routing to find the correct controller and action method, and provide parameters for the optional ID.

The Maproute method is also used to generate URLs through htmlhelpers such as ActionLink's controller, operation methods, and any routing data.

public static void RegisterRoutes (RouteCollection routes)

{

Routes. Ignoreroute ("{resource}.axd/{*pathinfo}");

Routes. MapRoute (

Name: "Default",

URL: "{controller}/{action}/{id}",

defaults:new {controller = "Balls", action = "Index",

id = urlparameter.optional}

);

}
Processing Post Requests
[HttpPost]

[Validateantiforgerytoken]

Public ActionResultone1 ([Bind (include= "Id,shenglv,releasedate,age,rongyu")] movie Movie)

{

if (modelstate.isvalid)

{

Db. Entry (Ball). state = entitystate.modified;

Db. SaveChanges ();

Return redirecttoaction ("Index");

}

Return View (ball);

}
Receives the data that the form is post and transforms the received balls request data to create a ball object.

The Modelstate.isvalid method is used to verify that the submitted form data can be used to modify (edit or update) a ball object.

If the data is valid data, it is saved to the ball collection of the database (Balldbcontext instance).

By calling Balldbcontext's SaveChanges method, the new data is saved to the database.

After the data is saved, the code redirects the user to the index action method of the Ballscontroller class, and the page displays the list, including the update that was just made.
Add search
Public ActionResult Index (string ballgenre, String searchstring)

{

var genrelst = new list<string> ();

var genreqry = from D in Db. Balls

D.genre

Select D.genre;

Genrelst.addrange (Genreqry.distinct ());

Viewbag.moviegenre = new SelectList (GENRELST);

var Balls = from M in db. Movies

Select M;

if (! String.IsNullOrEmpty (searchstring))

{

Balls = Balls.where (S =>s.title.contains (searchstring));

}

if (!string. IsNullOrEmpty (ballgenre))

{

Balls = balls.where (x = x.genre = = ballgenre);

}

Return View (Balls);

The verification of the method is mainly the verification of the input score and the score limit.

This project verification is a simple verification of the score of each game in volleyball.

The volleyball Scoring of MVC development (vii) Validation editing method

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.