I've been encountering issues trying to make a Get request to hit the specified URL. Initially, I attempted inputting the URL parameter manually in a separate JS file, then transitioning all my JS to cshtml to test out Razor. However, I am still facing a 404 error when making the request. Any assistance or guidance would be greatly appreciated, especially since I am relatively new to this.
function ShowMarketingMaterial() {
$.ajax({
url: "@Url.Action("GetMarketingMaterial", "MarketingMaterialController")",
type: "GET",
data: option,
dataType: 'json',
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
Below is my controller:
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Mvc;
using WebApplication2.Data;
using WebApplication2.Models;
namespace WebApplication2.Controllers
{
public class MarketingMaterialController : ApiController
{
private ImprevDBEntities db = new ImprevDBEntities();
[System.Web.Http.HttpGet]
public IHttpActionResult GetMarketingMaterial(string test)
{
var test1 = from M in db.DimMarketingMaterials
join I in db.DimListingIdentifiers on M.ListingId equals I.ListingId
where M.Url.StartsWith("https://client.marketing.imprev.net/")
&& I.ListingNumber == test
select new MarketingMaterial
{
UrlMaterial = M.Url,
Description = M.Description
};
var response = new MarketingMaterialsViewModel();
response.MarketingMaterials = new List<MarketingMaterial>();
response.MarketingMaterials = test1.ToList();
return Ok(response);
}
}
}