razor

How to render JavaScript into MasterLayout section from partial view?

杀马特。学长 韩版系。学妹 提交于 2020-02-09 06:51:06
问题 Given MVC3 and Razor engine, I got _MasterLayout.cshtml @RenderSection("JavaScript", required: false) .. .. @RenderBody() .. View.cshtml with _MasterLayout.cshtml defined in _ViewStart.cshtml .. @Html.RenderAction("PartialView", "PartialController") .. PartialView.cshtml .. @section JavaScript { ........ } .. How can I make sure that JavaScript from Partial View ends up in the Master Layout section? Edit The above scenario doesn't work because the partial view doesn't have a master layout

Passing response from ajax call to view in C#

血红的双手。 提交于 2020-02-06 09:08:23
问题 I am using ajax to call an action in the controller. The code is like this $('#kitchen').change(function () { var selectedKitchen = $('#kitchen').val(); if (selectedKitchen != '') { console.log("selected item:" + $('#kitchen').val()); $.ajax({ type: "GET", url: "/Home/GiveInsitutionsWithoutResponsibility", data: "id=" + selectedKitchen, dataType:'json', success: function (result) { result = JSON.parse(result); console.log(result.length); }, error: function (error) { console.log("There was an

Passing response from ajax call to view in C#

我们两清 提交于 2020-02-06 09:07:33
问题 I am using ajax to call an action in the controller. The code is like this $('#kitchen').change(function () { var selectedKitchen = $('#kitchen').val(); if (selectedKitchen != '') { console.log("selected item:" + $('#kitchen').val()); $.ajax({ type: "GET", url: "/Home/GiveInsitutionsWithoutResponsibility", data: "id=" + selectedKitchen, dataType:'json', success: function (result) { result = JSON.parse(result); console.log(result.length); }, error: function (error) { console.log("There was an

Passing response from ajax call to view in C#

允我心安 提交于 2020-02-06 09:06:11
问题 I am using ajax to call an action in the controller. The code is like this $('#kitchen').change(function () { var selectedKitchen = $('#kitchen').val(); if (selectedKitchen != '') { console.log("selected item:" + $('#kitchen').val()); $.ajax({ type: "GET", url: "/Home/GiveInsitutionsWithoutResponsibility", data: "id=" + selectedKitchen, dataType:'json', success: function (result) { result = JSON.parse(result); console.log(result.length); }, error: function (error) { console.log("There was an

json success and fail response in MVC

☆樱花仙子☆ 提交于 2020-02-06 07:36:13
问题 I'm practicing Ajax! I have a simple contact form and this is my actions : public ActionResult Contact() { return View("Contact"); } [HttpPost] public ActionResult Contact(ContactViewModel contactViewModel) { if (ModelState.IsValid) { var contact = contactViewModel.ConvertToContactModel(); _contactRepository.Add(contact); _contactRepository.Save(); return Json(new { msg = "Your contact Sent, I'll response soon." }); } return Json("Sorry! Somthing went wrong, try again or contact again"); }

json success and fail response in MVC

ε祈祈猫儿з 提交于 2020-02-06 07:36:09
问题 I'm practicing Ajax! I have a simple contact form and this is my actions : public ActionResult Contact() { return View("Contact"); } [HttpPost] public ActionResult Contact(ContactViewModel contactViewModel) { if (ModelState.IsValid) { var contact = contactViewModel.ConvertToContactModel(); _contactRepository.Add(contact); _contactRepository.Save(); return Json(new { msg = "Your contact Sent, I'll response soon." }); } return Json("Sorry! Somthing went wrong, try again or contact again"); }

json success and fail response in MVC

折月煮酒 提交于 2020-02-06 07:36:07
问题 I'm practicing Ajax! I have a simple contact form and this is my actions : public ActionResult Contact() { return View("Contact"); } [HttpPost] public ActionResult Contact(ContactViewModel contactViewModel) { if (ModelState.IsValid) { var contact = contactViewModel.ConvertToContactModel(); _contactRepository.Add(contact); _contactRepository.Save(); return Json(new { msg = "Your contact Sent, I'll response soon." }); } return Json("Sorry! Somthing went wrong, try again or contact again"); }

CompilationFailedException when using IRazorViewEngine in non Sdk.Web projects to render Razor pages

烈酒焚心 提交于 2020-02-05 14:56:12
问题 I am trying to use IRazorViewEngine in a console application <Project Sdk="Microsoft.NET.Sdk"> (not <Project Sdk="Microsoft.NET.Sdk.Web"> ) to render a .cshtml page in memory. I registered every needed dependency in the ServiceProvider . While calling the following line I get a CompilationFailedException : _viewEngine.GetView(directory, name, true); Exception: Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred: kmcajniq.bah(4,20):

How to pass data from Razor View Kendo UI DropDownList to Controller Variable?

♀尐吖头ヾ 提交于 2020-02-04 10:43:05
问题 vs'12 , KendoUI, asp.net C# MVC4 Internet Application EF Code First Would like to see how one would pass values form a KendoUI DropDownList to a MVC Controller from a Razor View Controller [HttpPost] //[AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(ViewModelCCTRST model) //, FormCollection values) { if (ModelState.IsValid) { string clt = model.Clients; string cnt = model.Countys; string twn = model.TownShips; ... ... //string xx = values["Clients"]; // xx = values["Countys"]; // xx =

Form Post from View Component

醉酒当歌 提交于 2020-02-04 05:04:42
问题 I'm building a small web application to test the new ASP.NET Core MVC. I implemented a View Component that comprises a login form that I need to insert into various places throughout the application. My form currently posts data to a normal Controller that handles the login. Now given that the user provided wrong login information I want to add an error message to the model state and display it under my form, like normal validation. But the thing is since the view component can be integrated