Hi All,
I am blocked on the additional challenge (task 15) of the project Resume Templater from ASP.Net skill path. In particular I am not able to complete the last point of this task:
Link:
- Navigate to /Models/Link.cs. Create another model class called
Link
, with propertiesLinkType
andURLPath
that a PageModel can set to pass it to the partial to render. The class should have a constructor that takes in alinkType
of typeLinkType
(you can create anenum
property for this holdingGithub
andLinkedIn
) and aurlPath
of typestring
.
For more information on the enum property please visit the official documentation
- Update the _Links.cshtml partial to use
Link
as the new model andURLPath
as the placeholder for the URL usernames. - Update the use of the partial in Index.cshtml and Projects.cshtml to use a new instance of
Link
and pass in the correct values forlinkType
andurlPath
in the constructor.
following their suggestion:
Link:
- Create an
enum
property,LinkType
, that will hold only two values:Github
andLinkedIn
. We can then create a new property,Type
, of data typeLinkType
and use it in the constructor. - The _Links.cshtml partial access the
URLPath
using the@Model
keyword:@Model.URLPath
. - Instead of using the
for
attribute, we can pass in a new instance ofLink
through themodel
attribute:model="@new Link(LinkType.GitHub, Model.GithubUsername)"
It give me an error about the name “LinkType” don’t exist. Following mine implementation for this point:
Link.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ResumeTemplater.Models
{
// Additional Challenge
public class Link
{
public enum LinkType
{
Github,
LinkedIn,
}
public string URLPath {get; set;}
public LinkType Type {get; set;}
public Link(LinkType linkType, string urlPath)
{
Type = linkType;
URLPath = urlPath;
}
}
}
_Links.cshtml:
<!-- _Links.cshtml -->
@model Link
<!-- Create partial below -->
@if(ViewData["Title"]=="Home")
{
<a asp-protocol="https"
asp-host="www.linkedin.com"
asp-controller="@Model.URLPath">
@Model.Type
</a>
}
else if (ViewData["Title"]=="Projects")
{
<a asp-protocol="https"
asp-host="github.com"
asp-controller="@Model.URLPath">
@Model.Type
</a>
}
index.csh (esecution of the partial):
<partial name="_Links" model = "@new Link(LinkType.LinkedIn, Model.LinkedInUsername)"/>
Thanks to everyone will help