Jayraj Goswami

Jayraj Goswami

  • NA
  • 198
  • 12.4k

Different Method not call webapi Project to MVC Project

Feb 17 2016 1:56 AM
This is My Webapi Controller Method
 
static readonly IRegCls RegObj = new SampleApplicationWebApi.Models.MyTest.RegCls();
public HttpResponseMessage GetFirstName(RegistrationMst ObjReg)
{
RegistrationMst Users = RegObj.GetFirstName(ObjReg);
if (Users == null)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "S O R R Y");
}
else
{
return Request.CreateResponse<RegistrationMst>(HttpStatusCode.OK, Users);
}
}
public HttpResponseMessage GetLastName(RegistrationMst ObjReg)
{
RegistrationMst Users = RegObj.GetLastName(ObjReg);
if (Users == null)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "S O R R Y");
}
else
{
return Request.CreateResponse<RegistrationMst>(HttpStatusCode.OK, Users);
}
}
 
 
How to call different Method  in my MVC Project
 
My Calling 
This MVC Controller 
[HttpPost]
public ActionResult GetFirstName(RegistrationMst RejObj)
{


var client = new HttpClient();
var response = client.PostAsJsonAsync("http://localhost:43536/api/RegAPI", RejObj).Result;

if (response.IsSuccessStatusCode)
{
}
return RedirectToAction("Index", "Home");
}
[HttpPost]
public ActionResult GetLastName(RegistrationMst RejObj)
{


var client = new HttpClient();
var response = client.PostAsJsonAsync("http://localhost:43536/api/RegAPI/GetLastName", RejObj).Result;

if (response.IsSuccessStatusCode)
{
}
return RedirectToAction("Index", "Home");
}
 
 
 
Current Issue is Method Not Fount
 
 
<input type="submit" value="Test11" class="btn btn-def btn-block button" formaction="/MyTest/GetLastName" /> 
 

Answers (1)