C
C#2y ago
Theos

Url.Action not working [NOT SOLVED]

Hey, I am trying to make a simple popup in which i could fill some info and then save it to database. I am using Url.Action for opening the popup
7 Replies
Theos
Theos2y ago
The problem is <button type="button" class="btn btn-primary" data-toggle="ajax-modal" data-taget="#addHale" data-url="@Url.Action("Create")">Dodaj</button>
Theos
Theos2y ago
Theos
Theos2y ago
that when i open my website data-url is empty
using Microsoft.AspNetCore.Mvc;
using System;

namespace WebApp.Controllers
{
public class HaleController : Controller
{
public IActionResult Index()
{
return View();
}

[HttpGet]
public IActionResult Create()
{
return PartialView("_HalaPartial");
}
}
}
using Microsoft.AspNetCore.Mvc;
using System;

namespace WebApp.Controllers
{
public class HaleController : Controller
{
public IActionResult Index()
{
return View();
}

[HttpGet]
public IActionResult Create()
{
return PartialView("_HalaPartial");
}
}
}
this is my controller its in Controller/HaleController.cs return PartialView("_HalaPartial"); how can I now create a popup? I have a _HalePartial.cshtml inside Views folder
@{
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>test</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
}
@{
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>test</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
}
Theos
Theos2y ago
Theos
Theos2y ago
it looks like this when I click my button literally nothing happens i tried <input type="button" value="Create" onclick="location.href='@Url.Action("Create")'" /> and same effect location.href is just empty
Angius
Angius2y ago
Url.Action() takes two parameters The first one is the name of the controller The second one is the name of the action
RTXPower
RTXPower2y ago
Use asp taghelper instead? Something like
<a asp-controller="Speaker" asp-action="Index">All Speakers</a>
<a asp-controller="Speaker" asp-action="Index">All Speakers</a>