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