http://csharp-video-tutorials.blogspo...
Slides
http://csharp-video-tutorials.blogspo...
All ASP .NET MVC Text Articles
http://csharp-video-tutorials.blogspo...
All ASP .NET MVC Slides
http://csharp-video-tutorials.blogspo...
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatAr...
In this video we will discuss using FormCollection object in mvc and it's purpose. Please watch Part 12, before proceeding with this video.
FormCollection class will automatically receive the posted form values in the controller action method, in key/value pairs. Keys & values can be accessed using key names or index.
We implemented "Create" view in Part 12.
We can use the FormCollection to loop thru each key and it's value that is posted to the server.
[HttpPost]
public ActionResult Create(FormCollection formCollection)
{ if (ModelState.IsValid) { foreach (string key in formCollection.AllKeys) { Response.Write("Key = " + key + " "); Response.Write("Value = " + formCollection[key]); Response.Write("[br/]"); } } return View();
}
Create the following stored procedure to insert employee data into tblEmployee table
Create procedure spAddEmployee
@Name nvarchar(50),
@Gender nvarchar(10),
@City nvarchar(50),
@DateOfBirth DateTime
as
Begin
Insert into tblEmployee (Name, Gender, City, DateOfBirth)
Values (@Name, @Gender, @City, @DateOfBirth)
End
Add the following method to EmployeeBusinessLayer.cs file.
public void AddEmmployee(Employee employee)
{ string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("spAddEmployee", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter paramName = new SqlParameter(); paramName.ParameterName = "@Name"; paramName.Value = employee.Name; cmd.Parameters.Add(paramName); SqlParameter paramGender = new SqlParameter(); paramGender.ParameterName = "@Gender"; paramGender.Value = employee.Gender; cmd.Parameters.Add(paramGender); SqlParameter paramCity = new SqlParameter(); paramCity.ParameterName = "@City"; paramCity.Value = employee.City; cmd.Parameters.Add(paramCity); SqlParameter paramDateOfBirth = new SqlParameter(); paramDateOfBirth.ParameterName = "@DateOfBirth"; paramDateOfBirth.Value = employee.DateOfBirth; cmd.Parameters.Add(paramDateOfBirth); con.Open(); cmd.ExecuteNonQuery(); }
}
To save form data, to a database table, copy and paste the following code in EmployeeController.cs file.
[HttpPost]
public ActionResult Create(FormCollection formCollection)
{ Employee employee = new Employee(); // Retrieve form data using form collection employee.Name = formCollection["Name"]; employee.Gender = formCollection["Gender"]; employee.City = formCollection["City"]; employee.DateOfBirth = Convert.ToDateTime(formCollection["DateOfBirth"]); EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer(); employeeBusinessLayer.AddEmmployee(employee); return RedirectToAction("Index");
}
Do we really have to write all the dirty code of retrieving data from FormCollection and assign it to the properties of "employee" object. The answer is no. This is the job of the modelbinder in MVC. We will discuss modelbinders in our next video.
asp.net core docker Part 13 FormCollection in mvc | |
533 Likes | 533 Dislikes |
281,226 views views | 524K followers |
Education | Upload TimePublished on 12 May 2013 |
Related keywords
wcf vs web api,ado.net core,sql server management studio,webkinz,purpose soap,webadvisor,used auto parts,craigslist nj,wcf one piece,asp.net core 3,ajax players,values quotes,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,values clarification,used trucks for sale,used jeep wrangler,values and beliefs,services angular,ajax ontario,asp.net mvc tutorial,purpose definition,asp.net cos'è,csharp assembly,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,asp.net zero,csharp foreach,server memes,used tesla model s,used golf clubs,sql date format,services online,chase,serverless architecture,server resume,wcf c#,server books,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,ajax deadpool,server jobs,values and morals,cvs,website,mvc tutorial,costco hours,wcf service application,values assessment,tutorialspoint spring,serverless,wcf soap,wcf cat,purposefully,wcf test client,cool math games,purpose of tonsils,purpose quotes,values statement,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,mvconnect,asp.net guida,cunyfirst,wcf nba,csharp download,wcfi foundation,csharp online,wcf authentication,tutorials near me,values in action,http://asp.net,server 2019,ado.net descargar,web of dreams,chernobyl,serverminer,ajax cleaner,values worksheet,ado.net visual studio 2019,webassign,ado.net vs entity framework,used cars for sale,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,use credit union,mvc architecture,used tires,http://ado.net,asp.net core mvc,purpose face wash,ajax soccer,server hosting,values matter miami,wcfi,ajax dish soap,purpose church,capital one,server rack,tutorialspoint html,csharp interface,purpose driven life,craigslist,values in action cvs,used books,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,tutorialspoint python 3,sql developer,webster,services transmission company sas,sql group by,asp.net core signalr,services manager,used tires near me,mvc framework,ajax paving,mvc near me,userbenchmark,purpose in spanish,used car values,values exercise,tutorialspoint spring boot,values card sort,mvc map,csharp online compiler,asp.net download,sql between,ado.net c# pdf,wcf 2019 nba,services tag dell,csharp switch,ado.net ventajas y desventajas,purposely,csharpstar,wcf tutorial,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,csharp string format,central park 5,values definition,ado.net c#,asp.net core github,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,server error in '/' application,services windows,asp.net core 3.0,purpose synonym,sql injection,wcf ria services,tutorialspoint c#,calculator,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,sqlyog,asp.net core 3 release date,sql server,server job description,purpose of life,tutorials by a,servicenow,webcam,mvc hours,webmd symptom,csharp array,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,purpose lyrics,webcrims,cheap flights,asp.net core hosting,services sas,used tesla for sale,tutorialspoint java,tutorialspoint java compiler,values in life,webmd,csharp to json,username generator,used boats for sale,college football,ado.net dataset,csharp dictionary,purpose meaning,values examples,cnn,website builder,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,mvc nj,tutorialspoint spark,ado.net oracle,asp.net core download,purpose justin bieber,csharp to vb.net,webster bank,used cars,webstaurant,values quiz,tutorialsystems,ajax post,services fms publish announcement,services.msc no abre,used tesla model 3,ajax jersey,csharp operator,asp.net core razor pages,values to live by,server duties,asp.net core environment variables,csharp random,century 21,purpose statement,services consultores,services consulting,mvcsd,mvcsc,services.msc,ado.net pdf,asp.net core configuration,ajax marvel,sql update,asp.net tutorial,mvc medical,values synonym,purposed,purpose games,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,chase online,used tesla,wcf api,costco,used car dealerships,server jobs near me,webex,sql meaning,sql tutorial,sql commands,purposeful,ado.net entity framework,ajax tavern,tutorialsteacher,purpose of appendix,ajax javascript,values list,services desk,values meaning,ajax greek,usertesting,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,mvcu,asp.net core middleware,wcf web service,mvc webadvisor,web store,mvcc,webmail,mvci,mvctc,
Không có nhận xét nào:
Đăng nhận xét