using System.Web.Mvc; using System.Threading.Tasks;
namespace ValidateOnDbSide.Controllers { public class BusinessController : Controller { public async Task<string> DoSomething() { return await Task.Run(() => test()); } public string test() { return "test"; } } }
2. Controller
using System.Threading.Tasks;
namespace ValidateOnDbSide.Controllers { public class HomeController : Controller { CompanyEntities db = new CompanyEntities();
public async Task<ActionResult> Index() { BusinessController b = new BusinessController(); //Task c = b.DoSomething(); string res = await b.DoSomething();
Because this call is not awaited, execution of the current method
continues before the call is completed. Consider applying the 'await'
operator to the result of the call.
To fix it replace
public ActionResult Index() { BusinessController b = new BusinessController(); b.DoSomething();
return View(); }
with
using System.Threading.Tasks;
public async Task< ActionResult> Index() { BusinessController b = new BusinessController(); await b.DoSomething();
[Remote(action: "ValidateSalary", controller: "Home", ErrorMessage ="will never be displayed - it will display message returned by stored procedure")] public int Salary { get; set; }
with
[Remote(action: "ValidateSalary", controller: "Home", AdditionalFields = "FirstName,LastName", ErrorMessage ="will never be displayed - it will display message returned by stored procedure")] public int Salary { get; set; }