I currently have a view which returns an IEnumerable
collection of Technicians via the TechnicianViewModel
. The view model populates fine and displays the objects correctly.
However, at the moment I need someone to point me in the right direction with regards to selecting a specific technician.
If I was to click More Info
on the technician, an [HttpGet]
request would be initiated which would result in a queryString. And this is exactly what is against the requirements of this project.(Requirements of the project: no query string should appear in the URL)
Here is the view :-
@model IEnumerable<ActionAugerMVC.ViewModels.TechnicianViewModel>
<div class="row">
@foreach (var item in Model)
{
<div class="col-sm-6 col-md-3">
<div class="">
<div class="">
<div class="">
@item.UserName
</div>
<div class="">
Technician
</div>
</div>
<div class="">
<img src="~\imagesurl-@item.GenerateName()" class="img-responsive" alt="...">
</div>
<div class="">
<p class="overlay__desc">
@item.Bio
</p>
<ul class="overlay__social">
<li><a href="#"><i class="ion-social-twitter"></i></a></li>
<li><a href="#"><i class="ion-social-facebook"></i></a></li>
<li><a href="#"><i class="ion-social-skype"></i></a></li>
<li><a href="#"><i class="ion-social-whatsapp-outline"></i></a></li>
</ul>
<a href="@Url.Action("Profile","Technician",new { url = item.GenerateURL() })" class="btn btn-accent">More info</a>
</div>
</div>
</div>
}
</div> <!-- / .row -->
Here is the View Model :-
public class TechnicianViewModel
{
public Guid ID { get; set; }
public string UserName { get; set; }
public string Bio { get; set; }
public string GenerateName()
{
string str = GenerateURL();
str = str + ".jpg";
return str;
}
public string GenerateURL()
{
string phrase = string.Format("{0}", UserName);
string str = phrase.ToLower();
str = Regex.Replace(str, @"\s", "-");
return str;
}
}
How can I avoid my controller method being an [HttpGet]
as I had implemented here so that I can have the ID from the viewmodel object returned by the view.
[HttpGet]
[Route("technician/profile/calgary-{url}")]
public IActionResult Profile(Guid? ID,string url)
{
var Profile = unitOfWork.TechnicianRepository.GetByGuidId(ID);
return View(Profile);
}
In your View, change the link to the following:
You can get rid of the HttpGet and Route decorators on your controller method. Those will be taken care of by the default routing config: