|
It will work with any type that would work with a manual customers.OrderBy(c => c.SomeProperty) call.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am curious to know any free health monitoring dashboard exist for asp.net webform or mvc project which we can use it.
i search google and found one for asp.net core ASP.NET Core Real-time Performance Monitoring – Allan Hardy[^]
so please check my link and tell me anything such exist for asp.net webform or mvc4/5 project.
thanks
|
|
|
|
|
|
Hello, I am a Very New programmer in the MVC architecture and I am struggling with getting data from my controller to my view. I am in my last year of college and we are building a web application for a non profit organization that will track residents in their facility.
I am trying to query the database for the rooms table and select the rooms that have the IsOccupied field set to false.
Then I am filtering the returned query for a range of rooms and putting them in Wings and passing them to the view.
My struggles are with getting the room object from the controller to the view. Then in the view, burrowing down into the object and getting the room number out and displaying it.
Currently I have the following in my class.
public class Room
{
public int RoomID { get; set; }
[Display(Name = "Room Number")]
public int RoomNum { get; set; }
[Display(Name = "Is Occupied")]
public bool IsOccupied { get; set; }
}
My Controller code is:
public ActionResult Create()
{
//Query database for IsOccupied flag//
var AvailRoom = from s in db.Rooms
.Where(s => s.IsOccupied == false)
select s;
foreach (var room in AvailRoom)
{
if (room.RoomNum > 101 && room.RoomNum < 126)
{
IEnumerable<selectlistitem> EastSouth = new SelectList(room.RoomNum.ToString());
ViewBag.EastSouth = EastSouth;
}
}
My view code is:
@Html.Label("Available Rooms")
@Html.DropDownList("EastSouth")
Currently all I get when I compile is a dropdown box with 1, 2 and 5.
I am stumped. Any recommendations on where to go from here would be really appreciated.
|
|
|
|
|
You're looping through the rooms, but you're overwriting the EastSouth list each time.
You're also passing a string as the only parameter to the SelectList constructor. This will call the SelectList(IEnumerable)[^] overload, which will create a list item for each character in the string.
Change your code to pass the list of rooms to the SelectList constructor, along with the name of the property which contains the value and the text:
var AvailRoom = db.Rooms
.Where(s => s.IsOccupied == false)
.Where(s => s.RoomNum > 101 && s.RoomNum < 126)
;
ViewBag.EastSouth = new SelectList(AvailRoom, "RoomNum", "RoomNum");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
First off, I would like to apologize for my horrible code!!!! I reread my post and I am really embarrassed. But I guess it takes making a fool out of yourself to get better.
Thank you for your help. This worked like a champ.
|
|
|
|
|
i have creating url using routelink.
@Html.RouteLink("Edit", "PageWithId",
new
{
controller = "Customers",
action = "Edit",
id = item.CustomerID,
page = ViewBag.CurrentPage
})
i am using this routing PageWithId with route link
routes.MapRoute(
name: "PageWithId",
url: "{controller}/{action}/{page}/{id}",
defaults: new { controller = "Customers", action = "Edit", page = UrlParameter.Optional, id = UrlParameter.Optional }
);
i have 3 routing code in route.config file. here is all
routes.MapRoute(
name: "PageWithSort",
url: "{controller}/{action}/{page}/{SortColumn}/{CurrentSort}",
defaults: new { action = "Index", page = UrlParameter.Optional, SortColumn = UrlParameter.Optional, CurrentSort = UrlParameter.Optional }
);
routes.MapRoute(
name: "PageWithId",
url: "{controller}/{action}/{page}/{id}",
defaults: new { controller = "Customers", action = "Edit", page = UrlParameter.Optional, id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
when i run my program the route link generate url like http://localhost:55831/Customers/Edit/1/ALFKI
when i click on the link the Edit action is getting called but customer id is getting null where as ALFKI is there in url as customer id.
here is my edit action details
public ActionResult Edit(string id, int page)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Customer customer = db.Customers.Find(id);
if (customer == null)
{
return HttpNotFound();
}
ViewBag.CurrentPage = page;
return View(customer);
}
please tell me why id is getting null when ALFKI as passing as customer id?
thanks
|
|
|
|
|
The URL /Customers/Edit/1/ALFKI matches both the PageWithSort and PageWithId routes. As a result, the first matching route will be selected - PageWithSort - and the ALFKI string will be available as a parameter called SortColumn .
Since your action doesn't take a parameter called SortColumn , and the route doesn't contain any data for a parameter called id , the parameter will be set to null .
You can see this for yourself using the ASP.NET Routing Debugger[^] package.
You'll need to rename the parameters on your actions so that they match the parameters in the route. Since the PageWithSort route will match anything that the other two routes would, that's the one you need to match.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you sir....have a nice day 
|
|
|
|
|
HI,
suppose i am inserting new records in db and PK field may be identity type of may not. i am showing 10 records per page through skip() and take(). now how could i calculate page no where newly inserted record will appear.
give me some direction. thanks
|
|
|
|
|
It depends on many factors, such as indexing, sort order, etc.
The rest of it is clear mathematics.
|
|
|
|
|
i have seen a example of asp.net mvc routing code where two controller name has been referenced.
routes.MapRoute(
name: "test",
url: "{controller}/{action}/{page}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
defaults: new { action = "Index" }
);
just started working with asp.net mvc. so curious to know that what is the objective to mention controller or action name twice ?
in above example there is two defaults....when and why it is required.
just requesting anyone can explain the same with a nice example. thanks in advance
|
|
|
|
|
I don't know where you got that example from, but it's not valid C#. Not only are you missing a comma between the last two parameters, but you've specified the same named parameter twice.
Try to compile that code, and you'll get:
CS1740 Named argument 'defaults' cannot be specified multiple times
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
HI Sir,
please check this url asp.net mvc 4 - Using Url.RouteUrl() with Route Names in an Area - Stack Overflow[^]
in the above url you will see a example where two controller name has been mentioned.
here a small snippet.
context.MapRoute(
"UserHome",
"User/{id}",
new { action = "Index", controller = "Home", area = "User", id = 0,
httproute = true },
new { controller = @"Home", id = @"\d+" }
);
looking for your further guidance. thanks
|
|
|
|
|
That doesn't match the code in your question.
This code is calling the MapRoute(name, url, defaults, constraints)[^] overload. The second anonymous object represents the constrains on the route.
See: ASP.NET Routing: Adding Constraints to Routes[^]
It would probably be worth reading most of that article. (You can ignore the "Web Forms" section.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
sir can you give some direction that which area i need to fix in my code.
|
|
|
|
|
What code? You've shown two different code blocks, one of which won't compile. And you haven't described a problem that needs fixing with either one.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
|
thanks sir for reply.
i found the small definition and it is
Kubernetes is an open-source system for automating deployment, scaling and management of containerized applications that was originally designed by Google and donated to the Cloud Native Computing Foundation
but the image i posted it seems it is application health check apps....isn't ?
|
|
|
|
|
No,
Mou_kol wrote: Kubernetes is an open-source system for automating deployment ... If you want to know more then please go to the Kubernetes website and read the documentation.
|
|
|
|
|
Hi guys!
I am thinking of creating a payment getway like Payoneer to help my country, we are deprived of VISA cards. And the goal is to use our own currency to make local purchases.
Please help me guys.
Thank you! 
|
|
|
|
|
Please do not post in multiple places: it duplicates work and that annoys people.
You already have this in QA, so leave it there.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
My routing code is not working.
i am showing data in tabular format with sorting and pagination. my solution is working. when i hover mouse on column then url looks like
http://localhost:55831/Customers?page=2&SortColumn=CompanyName&CurrentSort=ContactName
when i click on pagination numeric link then url looks like
http://localhost:55831/Customers?page=3&SortColumn=ContactName
i want my url should look like
1) http://localhost:55831/Customers/2/CompanyName/ContactName
2) http://localhost:55831/Customers/3/ContactName
so i add one routing code. here it is
routes.MapRoute(
name: null,
url: "Customers/{page}/{SortColumn}/{CurrentSort}",
defaults: new
{
action = "Index",
page = UrlParameter.Optional,
SortColumn = UrlParameter.Optional,
CurrentSort = UrlParameter.Optional
}
);
after adding the above routing code url looks bit weird. now url looks like
http:
http:
so when i click on above links then i am not redirecting to proper controller and action rather getting error.
so it means there is some problem in code which i added as routing in route.config.cs file.
my full routing code
routes.MapRoute(
name: null,
url: "{controller}/{action}/{page}/{SortColumn}/{CurrentSort}",
defaults: new
{
action = "Index",
page = UrlParameter.Optional,
SortColumn = UrlParameter.Optional,
CurrentSort = UrlParameter.Optional
}
);
routes.MapRoute(
name: null,
url: "{controller}/{action}/{page}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
page = UrlParameter.Optional,
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
so please help me to get my desired url what i mention above. thanks
modified 2-Feb-18 5:25am.
|
|
|
|
|
Controller
public class CustomersController : Controller
{
public ActionResult Index(int page, string SortColumn, string CurrentSort)
{
return View();
}
}
route
routes.MapRoute(
name: "Customers",
url: "Customers/{page}/{SortColumn}/{CurrentSort}",
defaults: new
{
controller = "Customers",
action = "Index",
page = UrlParameter.Optional,
SortColumn = UrlParameter.Optional,
CurrentSort = UrlParameter.Optional,
}
);
razor markup
@Html.RouteLink("Click", "Customers", new { page = 1, SortColumn="CompanyName", CurrentSort="ContactName" })
@Html.RouteLink("Click", "Customers", new { page = 1, SortColumn = "CompanyName" })
|
|
|
|
|