Bootstrap for ASP.NET MVC
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 6<br />
}<br />
}<br />
parameters,<br />
skipIfExists: false);<br />
21. In the preceding code, we added the values captured in the <strong>for</strong>m by the user<br />
to a parameters collection. We also collected all the metadata about the<br />
selected object by using IEntityFrameworkService. This service expects<br />
a context type name as one of the parameters <strong>for</strong> its AddRequiredEntity<br />
method, so we'll pass in the name of the DbContext object the user selected<br />
on the <strong>for</strong>m.<br />
22. We'll then check whether the user is adding the scaffolded item to a folder, and<br />
we'll make a small assumption that the parent folder of the selected folder will<br />
be the Views folder. We'll then invoke the AddFileFromTemplate method.<br />
23. With the UI and view model in place, open the CustomTextTemplate.cs.t4<br />
ile.<br />
24. The top part of the template ile speciies the template language, in this<br />
case, C# as well as the extension that the template needs to output.<br />
Since we're going to scaffold a view, this should be .cshtml.<br />
25. We'll also declare all the variables names that will be passed into the template<br />
at the top. The following should be added to the top of the template ile:<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
26. The rest of the T4 markup <strong>for</strong> the template is as follows:<br />
@model .<br />
@{<br />
ViewBag.Title = "";<br />
[ 125 ]