FAQ Database Discussion Community


How to create view to display list of files in ASP.Net MVC 4 project

c#,asp.net-mvc,asp.net-mvc-4,viewbag
I am learning ASP.Net MVC 4 Programming. Currently, I want to display the list of files to the web page. Following is what I did till now. In the HomeController.cs I edited the Contact action as follows: public ActionResult Contact() { ViewBag.Message = "Your file page."; DirectoryInfo dirInfo = new...

Calling a Partial View and passing multiple ViewBag values as parameters

asp.net-mvc-4,viewbag
I have the following public ActionResult Index() { ViewBag.Stage1="Module1"; ViewBag.Stage2="Module2"; .... } Now within View I am calling a partial View and passing ViewBag @Html.Partial("MyMenu", new ViewDataDictionary(new { Stage1= ViewBag.Stage1, Stage2= ViewBag.Stage2})) But here I am getting error 'object' does not contain a definition for 'Stage1' I even tried using...

Pass an array to the view using viewbag

asp.net,viewbag
I have a code where I used checkbox in order for the user to choose his preferences. Here is the code in my controller. [HttpPost] public ActionResult Selected_Softwares(string[] type){ var results = db.Softwares_Reports_vw.Where(s => type.Contains(s.software_name)).OrderBy(s=>s.software_name); //here i tried to pass the parameter to viewbag ViewBag.type = type; return PartialView(results); }...

How create Dropdown list only using ViewBag in ASP.NET MVC 4?

asp.net-mvc-4,html-select,html.dropdownlistfor,viewbag
Here I have a model class.. public class MyDrop { public int id { get; set; } public string value { get; set; } } In my controller I use this code.... public ActionResult Index(){ var GenreLst = new List<MyDrop>(); MyDrop a = new MyDrop(); a.id = 1; a.value =...

MVC Razor use ViewBag as part of dynamic Image link

image,razor,model-view-controller,viewbag
I've got an MVC Application and I've got a ViewBag List of Items. I've got the List using Razor to show in a Modal popup and I was hoping to use said list, to dynamically display an image for each item in the list I'm hoping for something along the...

ViewBag does not show new line [closed]

asp.net,asp.net-mvc,asp.net-mvc-4,model-view-controller,viewbag
I want to show text on two separate lines for the page header: @section featured { <section class="featured"> <div class="content-wrapper"> <hgroup class="title"> <h1>@ViewBag.Message</h1> </hgroup> </div> </section> } I have the following code in controller: public ActionResult Login(string returnUrl) { StringBuilder sb = new StringBuilder(); sb.Append("Web Security Administration Portal"); sb.AppendLine(); sb.AppendLine();...

c# convert linq query to array and put in viewbag object reference is not set to an instance of an object

c#,asp.net-mvc,linq,object,viewbag
Try to do a simple query in my database and pass the results to the ViewBag but getting this error: Object reference is not set to an instance of an object. Please help me! var Query = from m in db.Favorites where m.ApplicationUserID == User.Identity.GetUserId() select m.AdID; ViewBag.LikedPostsID = Query.ToArray();...

Passing data to a view with MVC 6 EF

c#,asp.net-mvc,entity-framework,model-view-controller,viewbag
Since I've seen several people advising against using the ViewBag I was wondering how to do it correctly using: return View() I've read that you need to use so called ViewModels but those don't seem to apply when you are working with the Entity Framework. How do I pass data...

When should I use ViewBag/model?

c#,model,asp.net-mvc-5,viewbag
I think that using ViewBag is faster than model. My example is: In the action: public ActionResult MyAction() { ViewBag.Data = (from m in myDatabase.myTable select m).ToList(); } In the view: @foreach(var item in ViewBag.Data) { <tr> <td>@item.myColumn</td> </tr> } By using model: [Table("tbl_mytable")] public class MyTable() { public int...

ViewBag not declared in hybrid Webforms/MVC project

asp.net-mvc,razor,webforms,viewbag
I have an existing webforms project (.net 4.5.1) that I just added MVC to (I just created a new MVC project using Individual authentication and copied all of the bits to the Webforms project). When I navigate to something like Sitename/Home/index, it works fine and renders the page. However, when...

Too many character literals in MVC View

javascript,asp.net-mvc,viewbag
Question Background: I pass to my MVC view a ViewBag object which contain a list of items. These items are then added through the use of a For loop to a Javascript method called 'AddRows' which creates and adds a new HTML row to a table in the view. The...

MVC5: Insert new value into populated SelectList()?

c#,asp.net-mvc,razor,viewbag,selectlist
In my main INV_Assets controller of my MVC5 app, I have an method for Edit() which passes several populated SelectLists() via the ViewBag to allow users to select from all available entities for the relevant list in the other tables of my Database -- Note, if there is a better...

Not show data in razor mvc 5 ASP.Net

c#,asp.net,asp.net-mvc,linq,viewbag
var query = from c in db.TblKaryawans join o in db.TblKaryawanKeluargas on c.IDKaryawan equals o.IDKaryawan select new { c.Nama, o.Hubungan}; ViewBag.karyawan = query; return View(); view @foreach (var item in ViewBag.karyawan) { <li>@item.Hubungan</li> } Error : 'object' does not contain a definition for 'Hubungan' ...

System.Random in ViewBag not displaying as string?

c#,asp.net-mvc,razor,random,viewbag
All I am trying to do is create a random number in the Controller and pass it to the View. However when I run the application the View only displays 'System.Random' not a generated value. Here is my controller: // GET: /Products/Create public ActionResult Create() { Random randomID = new...

How to get second related value from List in ViewData MVC?

c#,asp.net-mvc,asp.net-mvc-4,viewstate,viewbag
I have customer list which is having all details like customerId,firstname,lastname GetAllCustomer() method code var customer = from d in dbContext.Customers select d; return customer.ToList(); In Index.cs I have bind firstname to dropdown list var customerData =GetAllCustomer(); ViewBag.customerfirstname = new SelectList(customerData.Select(t=>t.firstname)); index.cshtml @using (Html.BeginForm("Index", "Home", FormMethod.Get)) { <p> customer name...

Can't access value of view bag in view set in controller

asp.net-mvc,controller,viewbag
I am unable to access value of Viewbag.IsTeacher=i; in view. What i am doing wrong or there is some thing more to do to access value of view bag ? I want to add an 'if' condition depending on the value of Viewbag.IsTeacher=i;. Spend hours on this but could not...

How to put viewbag value as a variable in javascript/ jquery?

c#,jquery,asp.net-mvc,model-view-controller,viewbag
I try to put two variable in JQuery which came from viewbags : $("#btnAdd").click(function () { var url = dev + "/Legacy/PutContentInThematic"; var GroupingId = $("#GroupingId_Dialog").val(); var Title = $("#Title_Dialog").val(); var Synopsis = $("#Description_Dialog").val(); var image = $("#Image_Dialog").val(); var ThematicId = @ViewBag.thematicid //Here i can't put ';' var ThematicName =...