Note: Replace ] with GREATERTHAN and [ with LESSTHAN symbol
Templated helpers are introduced in mvc 2. These built in templated helpers can be broadly classified into 2 categories.
1. Display Templates
2. Editor Templates
There are 3 DISPLAY templated helpers
@Html.Display("EmployeeData") - Used with a view that is not strongly typed. For example, if you have stored data in ViewData, then
we can use this templated helper using the key that was used to store data in ViewData.
@Html.DisplayFor(model =] model) - Used with strongly typed views. If your model has properties that return complex objects, then
this templated helper is very useful.
@Html.DisplayForModel() - Used with strongly typed views. Walks thru each property, in the model to display the object.
Along the same lines, there are 3 EDIT templated helpers
@Html.Editor("EmployeeData")
@Html.EditorFor(model =] model)
@Html.EditorForModel()
To associate metadata with model class properties, we use attributes. In the previous sessions of this video series, we have
discussed about using various data annotations attributes. These templated helpers use metadata associated with the model to
render the user interface.
The built-in display and edit templated helpers can be very easily customised. We will discuss this in a later video session.
We will use the following Employee class that we have been working with in the previous sessions.
[MetadataType(typeof(EmployeeMetadata))]
public partial class Employee
{
}
public class EmployeeMetadata
{ [HiddenInput(DisplayValue = false)] public int Id { get; set; } [ReadOnly(true)] [DataType(DataType.EmailAddress)] public string EmailAddress { get; set; } [ScaffoldColumn(true)] [DataType(DataType.Currency)] public int? Salary { get; set; } [DataType(DataType.Url)] [UIHint("OpenInNewWindow")] public string PersonalWebSite { get; set; } [DisplayAttribute(Name = "Full Name")] public string FullName { get; set; } [DisplayFormat(DataFormatString = "{0:d}")] public DateTime? HireDate { get; set; } [DisplayFormat(NullDisplayText = "Gender not specified")] public string Gender { get; set; }
}
Copy and paste the following Details action method in HomeController. Notice that, the employee object is stored in ViewData using
"EmployeeData" key.
public ActionResult Details(int id)
{ SampleDBContext db = new SampleDBContext(); Employee employee = db.Employees.Single(x =] x.Id == id); ViewData["EmployeeData"] = employee; return View();
}
For the code in Details.cshtml view please refer to my blog using the link above. Since our employee object is in ViewData, we are using @Html.Display("EmployeeData") templated helper. At the moment "Details.cshtml" view does not have a Model associated with it. So it is not a strongly typed view.
At this point, if you run the application, you should be able to view Employee details, as expected.
Now, change the implementation of "Details" action method with in home controller as shown below. Notice that, instead of storing
the "Employee" object in ViewData, we are passing it to the View.
public ActionResult Details(int id)
{ SampleDBContext db = new SampleDBContext(); Employee employee = db.Employees.Single(x =] x.Id == id); return View(employee);
}
Change Details.cshtml view using the code from my blog. We have specified "Employee" as the model object. So, here we are working with a strongly typed view, and hence we are using @Html.DisplayFor(model =] model) templated helper. Since, none of the properties of Employee class return a complex object, the ideal choice here would be, to use @Html.DisplayForModel() templated helper. In either cases, in this scenario you will get the same output.
You work with Editor templates in the same way. In HomeController, implement Edit action method as shown below.
public ActionResult Edit(int id)
{ SampleDBContext db = new SampleDBContext(); Employee employee = db.Employees.Single(x =] x.Id == id); return View(employee);
}
and copy the code for Edit.cshtml view from my blog.
Text version of the video
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...
asp.net core docker Part 44 Display and edit templated helpers in asp net mvc | |
| 180 Likes | 180 Dislikes |
| 83,623 views views | 524K followers |
| Education | Upload TimePublished on 27 Jun 2013 |
Related keywords
wcf vs web api,ado.net core,sql server management studio,webkinz,display inline-block,webadvisor,craigslist nj,viewing,wcf one piece,asp.net core 3,viewfruit,ajax players,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,viewshare mini login,model t,model s,services angular,ajax ontario,templates for invitations,templates free,templates for business cards,asp.net mvc tutorial,display driver,asp.net cos'è,csharp assembly,displayport cable,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,templates for certificates,asp.net zero,csharp foreach,server memes,sql date format,services online,chase,model cars,serverless architecture,display flex css,server resume,view as facebook,wcf c#,server books,tutorialspoint javascript,view park hotel,mvcc connect,ado.net mysql,view-sourcehttps //www.facebook.com,services technologies gps,display resolution,templates for resumes,templates definition,ajax deadpool,display flex,server jobs,modeling agencies,model x,cvs,website,model y,mvc tutorial,costco hours,display meaning,wcf service application,tutorialspoint spring,serverless,wcf soap,templates for instagram,wcf cat,cool math games,wcf test client,displayport,model o mouse,view source,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,mvconnect,cunyfirst,asp.net guida,wcf nba,templates for google slides,csharp download,wcfi foundation,csharp online,wcf authentication,tutorials near me,model s tesla,display driver uninstaller,http://asp.net,server 2019,chernobyl,ado.net descargar,web of dreams,serverminer,ajax cleaner,model t ford,ado.net visual studio 2019,webassign,ado.net vs entity framework,templates in gmail,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,mvc architecture,http://ado.net,modelo negra,display wallpaper,asp.net core mvc,ajax soccer,server hosting,wcfi,display price in bangladesh,ajax dish soap,capital one,templates in outlook,server rack,tutorialspoint html,csharp interface,craigslist,templates for word,templates for google sheets,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,mvc framework,ajax paving,mvc near me,tutorialspoint spring boot,mvc map,csharp online compiler,asp.net download,sql between,modeling clay,ado.net c# pdf,services tag dell,wcf 2019 nba,csharp switch,ado.net ventajas y desventajas,templates for invoices,csharpstar,wcf tutorial,modeling,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,central park 5,csharp string format,viewshare,view meaning,ado.net c#,asp.net core github,viewshare mini,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,sql injection,tutorialspoint c#,wcf ria services,calculator,viewpoint,ado.net entity data model,sql insert,tutorialspoint tableau,displayport vs hdmi,services google play apk,view quotes,model engine kits,sqlyog,asp.net core 3 release date,sql server,view-sourcehttps //m.facebook.com/ _rdr,server job description,tutorials by a,servicenow,templates pathfinder,webcam,mvc hours,webmd symptom,displayport to hdmi,csharp array,display picture,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,model x tesla,view synonym,cheap flights,webcrims,asp.net core hosting,services sas,model a ford,tutorialspoint java,modells,tutorialspoint java compiler,view-sourcehttps //m.facebook.com/home.php,webmd,csharp to json,templates in excel,college football,ado.net dataset,csharp dictionary,cnn,website builder,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,tutorialspoint spark,mvc nj,ado.net oracle,asp.net core download,csharp to vb.net,viewshare diamond,webster bank,webstaurant,tutorialsystems,ajax post,services fms publish announcement,services.msc no abre,modelo abv,ajax jersey,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,century 21,services consultores,services consulting,mvcsd,services.msc,mvcsc,ado.net pdf,asp.net core configuration,ajax marvel,sql update,asp.net tutorial,mvc medical,templates c++,viewster,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,display device,chase online,display css,display advertising,wcf api,costco,server jobs near me,webex,sql meaning,sql tutorial,sql commands,templates for pages,display block in css,ado.net entity framework,ajax tavern,tutorialsteacher,ajax javascript,services desk,viewfinder,model 3,templates for flyers,ajax greek,csharp tutorial,mvc pattern,templates for paper flowers,ado.net sql server,ado.net connection,display table,asp.net identity,mvcu,modelo beer,asp.net core middleware,viewpoint panel,viewsonic,modelo especial,wcf web service,mvc webadvisor,web store,mvcc,templates for google docs,webmail,mvci,mvctc,display test,
Không có nhận xét nào:
Đăng nhận xét