ASP.Net Project Resume Templater

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:

  1. Navigate to /Models/Link.cs. Create another model class called Link, with properties LinkType and URLPath that a PageModel can set to pass it to the partial to render. The class should have a constructor that takes in a linkType of type LinkType (you can create an enum property for this holding Github and LinkedIn) and a urlPath of type string.

For more information on the enum property please visit the official documentation

  1. Update the _Links.cshtml partial to use Link as the new model and URLPath as the placeholder for the URL usernames.
  2. 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 for linkType and urlPath in the constructor.

following their suggestion:

Link:

  1. Create an enum property, LinkType, that will hold only two values: Github and LinkedIn. We can then create a new property, Type, of data type LinkType and use it in the constructor.
  2. The _Links.cshtml partial access the URLPath using the @Model keyword: @Model.URLPath.
  3. Instead of using the for attribute, we can pass in a new instance of Link through the model 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 :slight_smile:

HI, would like to know if you have found an answer to this yet?

Hi, I don’t know if you still need this solution but someone might read this post also so will be leaving it here:

So the problem that was being encountered is that the “LinkType” doesn’t exist.
This is the code before:

<p>For more information regaridng my experience, please refer to my <partial name="_Links" model="@new Link(LinkType.LinkedIn, Model.LinkedInUsername)"></p>

So what should it have been is that you should also specify the class name on the enum value that you are passing to the Link class. So the solution would be like this:

<p>For more information regaridng my experience, please refer to my <partial name="_Links" model="@new Link(Link.LinkType.LinkedIn, Model.LinkedInUsername)"></p>

So I’ve come up with these solution since I was debugging and trying to see the problem. I run the program without putting any parameter inside the object so it looked like this:

<p>For more information regaridng my experience, please refer to my <partial name="_Links" model="@new Link()"></p>

When I run the program, it was obviously gonna fail but it throws an interesting error:
image

It says: There is no argument given that corresponds to the required formal parameter ‘type’ of ‘Link.Link(Link.LinkType, string)’

Notice the first parameter? Link.LinkType, so that’s got me thinking. I was expecting it to be type LinkType, but was surprised that it was Link.LinkType. So I tried calling the enum by Link.LinkType.LinkedIn, and it worked!

1 Like

Hi, I don’t need it for now, anyway, thanks for replay

1 Like