AllramEst
AllramEst

Reputation: 1449

Pass AngularJS parameter to ActionResult method

I have google and tried a lot of different solutions to this problem, non of them worked. this is as far as I got. I tried passing it with a Action Link and a anchor tag. Tried catching it from the url in the ActionResult. This anchor tag produce the right url

HTML

    <a class="link btn btn-default" ng-href="@Url.Action("CloseProject", "Home")?id={{item.ID}}">@Resource.CloseProjectButton</a>

C#

public ActionResult CloseProject()
    {
        Guid id = new Guid(Request["id"]);

            _fastaSamarbetenRepo.UpdatePropertyBagItemStatusToClosed(id);

        return RedirectToAction("Projekt");
    }

what am I doing wrong?

Upvotes: 1

Views: 226

Answers (1)

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48357

You should pass the parameter using new keyword.

@{
 var url = Url.Action("CloseProject", "Home", new { id = "{{item.ID}}"});
 url = HttpUtility.UrlDecode(url);
}

and use data-ng-href.

<a class="link btn btn-default" data-ng-href="@url">@Resource.CloseProjectButton</a>

Upvotes: 1

Related Questions