0
votes

So I'm trying to write a bit of code that takes in a video from YouTube and adds it to a list. I'm doing this by passing in a url to a form and passing it to the controller. However, nothing happens.

View:

<form asp-action="addVideo" asp-controller="Video" validate="validate">
    <input name="vidUrl" type="url" placeholder="Search for a video" required="required"/>
    <input type="submit" value="Search"/>
</form>

Controller:

public ActionResult addVideo(string vidUrl)
{
    //Do stuff...
    return RedirectToAction("Index");
}

I have tried debugging addVideo, but submitting the form never triggered the breakpoint. The resulting url looks like http://(domain)/Video?vidUrl=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdTDy8XVdRSk

Is there a reason that the view isn't calling the controller?

Update:

I know what's causing the issue. It's definitely the asp-action and asp-controller tags. I have a navbar up on top of my web page that previously was controlled by razor statements like @Html.ActionLink("Home","Index","Home"). I tried switching this link to a set of anchor tags with the same controller and action values, but it has no effect on the website. Is this an issue with packages?

1
I've been reading this article on HTML forms and it may have to do with the absence of method="post" on my form tag. w3.org/TR/html401/interact/forms.html Is there something in Visual Studios that handles this issue and is not in other ide's? - Code Bird
That does change the result. The video url is no longer appended to the url in my browser. I'm guessing there is a routing issue involved. - Code Bird
After running more tests, it looks like the action I'm trying to call routes me to the same controller I'm trying to call, but it's just the index action and not the action I want. - Code Bird
Placed this into my view to test to see if I can force the action on my controller. <a>@Html.ActionLink("Test","addVideo","Video")</a> Press the link caused the web site to error out, saying that the action could not be found. - Code Bird
Adding [HttpGet] to method makes the anchor tag work. - Code Bird

1 Answers

0
votes

Found it, html tag helpers are a core feature, which my ide Xamarin does not support nor does it multitarget. I guess switching back to Visual Studio will suffice.