Posts

Showing posts with the label asp.net-mvc

ASP.NET When page edit Dropdown get value returning issue?

ASP.NET When page edit Dropdown get value returning issue? I have a these two table for Dropdown Db.Aletler: Id - Ad Db.Setaletler: Id - AletID Sample When save dropdown insert values in Db.Setaletler table Code public static List<Aletler> GetAlets() { using (CATSDDEntities db = new CATSDDEntities()) { var getallusedAlet = db.Setalets.ToList().Select(s => s.AletId).ToList(); return db.Aletlers.Include(s => s.AletAD).Where(s => !getallusedAlet.Contains(s.Ad)).ToList(); } } it working good now but when ı do edit go any data create page problem here not get values existing saved values. this time it does not get in dropdown when I enter the edit page for the registered items How are you populating the dropdown items ? You can exclude items there – Shyju Jun 30 at 0:18 ...

Why is my model and its variables not passing from View to Method inside of my Controller?

Why is my model and its variables not passing from View to Method inside of my Controller? My application searches for the files that contains a string the user is looking for. So far it does that perfectly. The last thing I need to do is to export it to an excel file so I added a method inside of my controller that is called by the Result page after I press a button. Result The results are stored in a List of type Result which is a class with four variables. List Result The method ExportToExcel currently returns string so that I can test if the list of results is null. Every single time it has come out as "No Data", therefore it is null. It perfectly prints out a table with the information in the Results page but does not have the information when i want to export it. ExportToExcel Results Why is my model not passing from view to method? At first I wanted to pass my model so that I can access the information in the List but now I am wondering if it would be better to s...

Adding Multiple Elements of a list to another in C#

Adding Multiple Elements of a list to another in C# I have some lists like this: List A={1,2,3} List B={10,20,30} List C={100,200,300} ... and I want something like this: List ABC1={1,10,100} List ABC2={2,20,200} List ABC3={3,30,300} How can I do this in C#? can anyone help me? Are the lists stored in another list? – Tim Schmelter 23 secs ago 1 Answer 1 Use Union: A.Union(B).ToList(); A.Union(B).ToList(); By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Add/Insert data using repository MVC

Add/Insert data using repository MVC I am currently being taught how to use MVC and my supervisor showed me how to use a repository with a read function but I'm stuck with implementing an Add function. This is my current code, thanks in advance! Repository: public void AddDriver(DriverModel model) { using (var db = new VehicleReservationEntities()) { var newDriver = new Driver(); newDriver.DriverLastName = model.DriverLastName; newDriver.DriverFirstName = model.DriverFirstName; newDriver.DriverLicense = model.DriverLicense; newDriver.LicenseExpiry = model.LicenseExpiry; newDriver.MobileNumber = model.MobileNumber; newDriver.BusinessUnit = model.BusinessUnit; newDriver.DateRegistered = model.DateRegistered; db.Driver.Add(newDriver); db.SaveChanges(); } } Controller: public ActionResult Add() { var repo = new Vehic...

pass value of a textbox from view to controller using actionlink

pass value of a textbox from view to controller using actionlink In my form I have a textbox as below @Html.TextBox("first_name") I need to pass the value of this textbox to controller through a actionlink. I tried the below @Html.ActionLink("View", "view_Details", new { name = first_name}) but this is giving error "first_name" does not exist in the current context Is this possible using a Actionlink? My controller signature is public ActionResult view_Details(string name) { return View(); } Edited @Html.ActionLink("View", "view_Details", new { name = getname()}) function getname() { return $("#first_name").val(); } I tried above code. Its also giving error getname() does not exist in the current context Your will need javascript/jquery to get the value of the textbox and then update the url – Stephen Muecke ...

Ensure that a specific exception always results in a given HTTP response status code

Ensure that a specific exception always results in a given HTTP response status code Requirement I have an ASP.Net MVC application that works with a number of different libraries. As with most libraries, various function calls may cause one of many different exceptions to be thrown. Currently, whenever any exception is thrown, then MVC application 'handles' them and returns an "internal server error" (code 500) back to the client (eg. web browser). This is fine for most cases, however, there is one specific exception type (in this case UnauthorizedAccessException ) that I would like to result in an "Unauthorized" (code 401) status being sent in the response, instead of the usual 500 error. UnauthorizedAccessException Current Attempt I did a fair bit of research and it looks like the bets way to 'catch' all exceptions and process them is by using the Application_Error method. So I tried the following implementation of Application_Error in the MvcApp...

How to handle data that's coming from from database in c#

How to handle data that's coming from from database in c# I think my connection has no problem. But when I run the program and opened browser with this link "http://localhost:1290/bolum/hello" I reached just Output: DKLSAJDKLJALSJDLs Q . How can I use my database data? My model,view,controller files are on the bottom. I removed "using .." lines when writing here. CONTROLLER namespace WebApplication4.Controllers { public class BolumController : Controller { public ActionResult Hello() { var bolum = new Hello() { Ad = "Q" }; Console.WriteLine("success"); MySqlConnection con = new MySqlConnection("server=localhost;database=proje;uid=root;password=123456;"); MySqlDataAdapter da = new MySqlDataAdapter("Select * From hasta_bilgileri", con); DataSet ds = new DataSet(); try{ con.Open(); } catch (...

How to redirect to external url from Web Api Services

How to redirect to external url from Web Api Services if (order.Payment_Mode == "ONLINE") { int amount = (int)order.Tot_Price; DateTime Today = System.DateTime.Now; string MerchantId = ""; // return Redirect("https://www.google.com/"); return Ok(); } I want to redirect to Payment gateway url by adding values in URL By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Method not found: “” in view? property remove automatically on restart debugging [on hold]

Method not found: “” in view? property remove automatically on restart debugging [on hold] I am using nop commerce 3.8 and i added a field in AddToCart class and when i run the code and debugging it it is working fine but if i restart the debugger then that property field is removed automatically from the AddToCart , same issue when i published the project and first time it is working fine but if i restart the iis server then the same issue occurred again, please help don't know why it is happening i tried all the solutions from the references like clean project replace the dlls and restart the visual studio and the old dlls lingering of old assembly, try to remove obj and bin folder but the issue is still same. This question appears to be off-topic. The users who voted to close gave this specific reason: I Got solution. please refer below link stackoverflow.com/questions/51129717/… – Polo 11 hours ago ...

Asp .net MVC Dropdownlist validation not working

Asp .net MVC Dropdownlist validation not working Here is my Code, Am in learning stage please some one help me. Have three issue 1)validation not working. 2)In controller side modelState is invalid. 3) How to reset dropdownlist after submit. public List<mstrClient> getCountry() { mstrClient objClientList = new mstrClient(); DataSet ds = new DataSet(); string sQuery = "SELECT * FROM INV_mstrCountry WHERE CStatus = 'Y'"; SqlDataAdapter da = new SqlDataAdapter(sQuery, con); con.Open(); da.Fill(ds); con.Close(); List<mstrClient> CountryList = new List<mstrClient>(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { mstrClient objClient = new mstrClient(); objClient.CountryCode = ds.Tables[0].Rows[i]["CountryCode"].ToString(); objClient.Country = ds.Tables[0].Rows[i]["CountryName"].ToString(); Count...

Disabled Package Manager Console because of error in reading packages.config

Disabled Package Manager Console because of error in reading packages.config Didn't find a solution for my problem on the net. My Package Manager Console is disabled because it says it can't read packages.config. Package Manager Console packages.config. An error occurred while reading file 'filepathpackages.config': There are duplicate packages: Microsoft.AspNet.WebApi.Core I know it says there are duplicate packages but there's not. On the net, there's solution for a failed restore or a couldn't find the package.config file. Nothing remotely close to my issue. I am trying to download typeahead.js . That's why I need the PMC. typeahead.js Couldn't help but ask the community. Kindly help. Thank you. "Kindly help." so commanding. Remove all the lines from your packages file and try again. Now add the lines back one at a time, retrying after each line, to find out which one is the problem. Once you've found...