asp.net-mvc-5

MVC 5 Web Attribute Routing is not working

自作多情 提交于 2019-12-13 17:36:56
问题 I implemented the Attribute routing in my Application and after that when I started nothing was working as planned. Only the Json Results works rest is not working as expected. [RoutePrefix("ProductCategory")] public class CategoryController : Controller { [Route("CategoryMain")] // GET: /Category/ public ActionResult Index() { var cat = categoryService.GetCategories(); if (Request.IsAjaxRequest()) { return PartialView("Index", cat); } return View("Index", cat); } } Error Server Error in '/'

Style messed up after nuget update.

筅森魡賤 提交于 2019-12-13 17:33:07
问题 I updated multiple nuget packages of default MVC application and my page style got messed up. Looks like partial styles are being loaded but I am unable to track down what went wrong. Thanks in advance. My Navbar before update. My Navbar after update. 回答1: Sorry to hear that. I got the same problem, and it cost me a lot. So frustrating. Fortunately I found the solution. It is because of the the new version of Bootstrap . To solve the problem, please follow the steps below: Right click on your

ActionLink to submit Model value

巧了我就是萌 提交于 2019-12-13 16:37:45
问题 I want my Ajax.ActionLink to pass a viewModel property to action. Here is my ViewModel public class ViewModel { public string Searchtext { get; set; } } My .cshtml @Ajax.ActionLink("Bottom3", "Bottom3",new { name = Model.Searchtext}, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "pointsDiv" }) using(Html.BeginForm("Bottom3", "Home", FormMethod.Get)) { @Html.TextBoxFor(x => x.Searchtext) <button type="submit">Search</button> } <div id="pointsDiv

Where does a WebApi 2.0 project store new users (when created with individual user authentication)?

ぐ巨炮叔叔 提交于 2019-12-13 16:24:24
问题 I've created a solution consisting of an MVC 5 project and a WebAPI 2.0 project, with the MVC project set to use No authentication settings and the WebAPI project set to use individual users authentication settings. I've also added a reference of my WebAPI project to my MVC project and configured the solution to use the MVC project as it's startup- the button's in the navbar take me to the views returned to me by the MVC controllers, but when visiting /api/values I get the XML results back,

Ajax get object from controller to view

安稳与你 提交于 2019-12-13 15:23:49
问题 model : public int Id { get; set; } public string Name { get; set; } public string Adres { get; set; } public string Surname { get; set; } controller: [HttpGet] public Student GetStudentById(int id) { var output = RepositoryFactory.Create<IStudentRepository>().GetByID(id); return output; } JS: .click(function () { $.ajax({ type: "GET", url: '/Admin/GetStudentById/', data: { id: object_id }, success: function (response) { $('#toolbox-text').val(response) } }) And the problem is that i want to

Why do I need a ToList() to avoid disposed context errors?

牧云@^-^@ 提交于 2019-12-13 12:26:15
问题 I'm writing some code to access a database using EntityFrameWork. The code is: public IEnumerable<Rows> GetRows(int id) { using (var context = new ApplicationDbContext()) { var repository = new EntityFrameWorkRepository<int, RowEntity>(context); //need a ToList() here to prevent disposed dbcontext errors return repository.GetRowsFromDb(id).ToList(); } } GetRowsFromDb() uses LINQ to query the database and filter the results using id. I originally wrote the above method without the ToList()

mvc 3 to mvc 5 migration razor syntax issue [closed]

﹥>﹥吖頭↗ 提交于 2019-12-13 11:29:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . We used official tutorial for upgradation, after following, we got no build errors, after running some functionalities are not working. We saw that some razor syntax were showing red as syntax error/some closing tag missing. what may be the reason edit: The errors as below image http://p.lui.li/img-40102_1_p-r

Mvc 5 pagination using view model

北城余情 提交于 2019-12-13 10:01:32
问题 Hi i am newbie to Mvc i have a json service which returns a list of walletstatementlogs based on fromdate and todate. I have a controller TopUpReqLogController every time when i hit the action index of the controller it will go to service and fetch the data and returns to view as Ipagedlist and genrates pagelinks. How do i prevent servicecall everytime in TopUpReqLogController index action i just want to load service data once and pass it to index and display data in pages using int ? page

How to call API in asp.net MVC5

筅森魡賤 提交于 2019-12-13 09:35:27
问题 I have asp.net mvc5 project that I want to call another API using JSON, and I want to call that API from my Controller action because I need to do some hashing in there, It's my first time doing this, and I need to send the request in JSON and also get responses in JSON all of that using the controller action. 回答1: If your method is POST : string uri = "yourdomain/api/controller/method; var client = new HttpClient(); var values = new Dictionary<string, string>() { {"username", SecurityHelper

Return string error message using ajax error function in mvc5 API2

梦想的初衷 提交于 2019-12-13 08:36:45
问题 I'm using API2 controller in mvc5, implementing CRUD operations. In POST method i have an if statement that return BadRequest() when IF statement result is false. [HttpPost] public IHttpActionResult CreateAllowance(AllowanceDto allowanceDto) { allowanceDto.AllowanceID = _context.Allowances.Max(a => a.AllowanceID) + 1; allowanceDto.Encashment = true; allowanceDto.Exemption = true; allowanceDto.ExemptionValue = 0; allowanceDto.ExemptionPercentage = 0; allowanceDto.CreatedDate = DateTime.Now;