Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search
  HOME    TRACKER    ASP.NET


Advertisements:










MVC :: Passing Boolean Values To View From Controller?


I'm having problems passing values from the controller to the view.I created a boolean variable to use as a flag and want the view to render some html based on whether its true or false.

Unfortunately ViewData doesn't look like it can pass boolean values.I should be able to pass any datatype to a view (string, int, bool, etc...)


View 16 Replies (Posted: Jan 20, 2010 02:55 AM)

Sponsored Links:

Related Forum Messages For ASP.NET category:
MVC :: Passing Model Object To View And From View To Controller?
I've got problem with my app .

I've got such classes (this is some kind of tree structure):

[Code]....

[Code]....

in Index() action i've got this piece of code

[Code]....

[Code]....

Posted: Aug 06, 2010 11:32 AM

View 2 Replies!   View Related
MVC :: Passing Data From Controller To View
I have setup an httppost that sends a string into my controller, searches for some results using linq, andthen sends the resultsto a view. In debug stepping through the code I can see the data that I am looking for being passed into the return view statement, but the page just appears to refresh (it doesn't render the view as expected with the result). why my controllerfails to redender the view? (note: I didn't include the view because I can send a ToList() to it without an issue. For example,return View(_entities.Persons.ToList());

[HttpPost]
public ActionResult RenderSearch(string usersearchtext)
{
if (usersearchtext != null)
{
var search_results = from s in _entities.Persons
where s.Description.Contains(usersearchtext)
select s;
return View("SearchResult", search_results.ToList());
}
else
{
throw new NotImplementedException();
}
}

Posted: Nov 16, 2010 08:17 PM

View 8 Replies!   View Related
MVC :: Passing Objects Between View And Controller?
I would like to pass List<SelectListItem> (not selected item but the whole "List" object) back to controller.

for example in my GET controller i would have this

ViewData["list"] = some select list from repository;

then on post I would like to get the list back from view..pretty much i'm trying to use ViewData["list"] as storage..this way I would use ajax to remove or add items to/from the list.

Posted: Sep 02, 2010 11:11 AM

View 10 Replies!   View Related
MVC :: Passing Parameters From View To Controller?
How do you pass values from aView to a Controller? I have an Html.DropDownListin a view, and need to get the selected value/text back to the controller.

[Code]....

[Code]....

Posted: Dec 23, 2009 06:38 PM

View 6 Replies!   View Related
Passing Data From A View To A Controller In MVC?
I have a dictionary I'm passing to a View. I want to be able to pass the values of that dictionary back to a Controller action from this same View. Is there anyway this can be accomplished without using a form? The situation is that I need to be able to pass these back to a controller action that is called when a user clicks an ActionLink from the View, and in my experience an ActionLink cannot be used to submit a values of a form, i.e. I've only been able to submit values of a form using the form's submit button. Unless there's a way to use an ActionLink to submit values in a form.Controller Action passes Dictionary to Controller in ViewData:

public ActionResult ModifyNewCrossListing(FormCollection form)
{
Dictionary<int, string> prefixlist = new Dictionary<int, String>();

[code]...

Posted: Apr 22 10 at 17:24

View 1 Replies!   View Related
MVC :: Passing Values From Controller To Service Layer?
I am working on Tenant module that has to display following fileds, Tenant Id, Tenant Desc, Contact Person, Contact Phone. In the DB, these are designed as two separate tables - Tenant and Contact. Tenant table has Tenant Id, tenant Desc and Contact Id . Contact table has all the contact related properties. I am using EF as DAL.

To make my system loosely coupled, I have created a repository pattern to talk to EF entities. Also, for validation I am using service layer.

My repository layer has two interfaces and classes corresponding to Tenant and Contact.

public interface ITenantRepository : IRepository<Tenant> // IRepository<T> is a generic interface for CRUD operations
{
Tenant Get(int id);
IEnumerable<Tenanr> List() ;

[Code]....

Posted: Mar 24, 2011 08:50 PM

View 4 Replies!   View Related
MVC :: Passing Data From View To The Controller With Dropdownlist
I have a table with a ID, CodeID,LibelleID field. I am using oracle connection. i want to display in a drop downlist (textfield) CodeID+LibelleID for exemple "100-SalaryBase" where CodeID=100 and LibelleID="SalaryBase" is it possible to obtain it if the user selects an element from the dropdownlist how to post both the codeID and ID to the controller

Posted: Jul 14, 2010 03:00 PM

View 4 Replies!   View Related
MVC :: Passing Data From View Back To Controller
I have following situation - I am pasing user info object from Controller to View. It contains GUID UserID, which i dont want to be seen on page. So I removed everyHtml.LabelFor(model => model.UserID),Html.TextBoxFor(model => model.UserID) etc... from generated View source. And because of this when Html.BeginForm() returns that object back toControllerall values is there but UserID is lost??

If I leaveHtml.LabelFor(model => model.UserID),Html.TextBoxFor(model => model.UserID) etc.. in View everything is fine. But I dont want to show UserID? Where is the problem here?

<%= Html.LabelFor(model => model.C__User_Id) %>

Posted: Sep 23, 2010 01:11 PM

View 6 Replies!   View Related
MVC :: Passing ViewModel With Data From View To Controller
I am trying to pass a view model of mine, which has multiple list in it, to my view. Then in my view i need to edit the different list. Then on my post i need to save the edits. Although, when i pass my viewmodel back to my post, it is empty! Can somebody explain what i am doing wrong? Controller

[Code]....
here is my View

[Code]....

NewsViewModel

[Code]....

Posted: Dec 13, 2010 07:19 PM

View 2 Replies!   View Related
MVC :: Passing A Select Item From View To Controller?
I have tried to get the dropdown box to work, no luck. That has to be me, but got tired of trying so I wrote a html helper extension and pass it the name and list of selectitems. Displays great (still need to work on showing selected items for edit functions but that is later)and can get it to work in other places, but not in this one instant and I can not figure out what I am doing wrong. Basically I have the form on the index view and want to send it to another action listconsulate (same controller).

On the form action I have tried consulate/listconsulate and a bunch of different combinations.

[Code]....

On the controller end I have tried the above, byval CC as Country, byval collection asFormCollection and a bunch of others. I have tried break points but they never fire on the listconsulate action and it always returns the index view. What am I doing wrong. I have tried the form code on like a listconsulate view so that it post back to itself, I am having a hard time getting any values to show up anywhere.

Posted: Apr 29, 2009 03:00 AM

View 5 Replies!   View Related
MVC :: Passing Model Back From View To Controller?
I really need your advice on this. User will upload a list of students information from a CSV file. After the upload has completed,the Controller will pass the Student model to a View. The View will display thelist of uploaded Students. On the View, there is also a checkbox "Create Logon Account" and a submit button. If the checkbox is checked, and the submit button is clicked, logon accounts will be created for the list of Students.

The problem is after displaying the list of Students on the View with the model, how can I pass the same model back to the Controller for creation of logon accounts?

I have managed to do it using FormCollection but I am wondering is there a better way.

Posted: Sep 22, 2009 01:28 AM

View 3 Replies!   View Related
Passing A List Of Object From A View To The Controller In Mvc?
ss a list of objects as a paramter in an actionlinkAt the moment when I try to do this the list is always empty by the time it reaches the controller!

<%= Url.Action("ActionName", new { list = Model.ListOfObjects}) %>
public ActionResult ActionName(List<Object> list)
{
//Do stuff
}

Posted: Mar 26 10 at 12:15

View 3 Replies!   View Related
MVC :: Passing SQL Query Results From Controller To View?
What's the best way to run a sql query in a controller action and pass the results to a view to be databinded to a listview? I tried:

[Code]....

But it returns "No results" (the EmptyDataTemplate) every time, even when the query has results. Thus, I think something is wrong with the databind.

Posted: Oct 16, 2009 02:45 PM

View 1 Replies!   View Related
MVC :: Methods To Passing Additional Data From Controller To View
I am getting started with Ap.net MVC. For that i chose to practice it by build an application. Im using MVC 2 and Linq To SQL, and i would like to passing another Query to the view. For example, i have this:

[Code]....

So i would like to pass data1 and data2 to the View. I can use return View(data1), but the View function accept just one data. So what technique i can use to pass the tow data to the view

Posted: Apr 29, 2010 03:34 AM

View 5 Replies!   View Related
MVC :: Passing A List Of Entity Objects To View From Controller?
I need to pass a list of Entity Objects from Controller to View but not put it in the Model context. It is the users homepage, but I am putting a list of alerts on the users home page(somewhat like facebook). So I need the User Context as the Model I pass but need to pass the Alert model as well so I can show the list of alerts.. How would I do that? The code below is what I have so far..

UserController

[Code]....

UserRepository

[Code]....

Posted: Aug 05, 2010 01:04 AM

View 1 Replies!   View Related
Passing Data From Controller To View Using JSon Object
I have the following to get the Json abject passed from the controller and populate the various textboxes in the view. However, nothing is happening even though controller is passing a valid Json object. What is wrong with this code?

<script language="javascript" type="text/javascript">
$(document).ready(function() {
var url = '<%=Url.Action("DropDownChange") %>';
$("#vendorID").change(function() {
var selectedID = $(this).val();
if (selectedID != "New Vendor Id") {
//$.post('Url.Action("DropDownChange","Refunds")', function(result) {
$.post(url, { dropdownValue: selectedID }, function(result) {
alert(selectedID);
$("#name").val(result.Name);
$("#city").val(result.City);
$("#contact").val(result.Contact);
$("#address2").val(result.Address2);
$("#address1").val(result.Address1);
$("#state").val(result.State);
$("#zip").val(result.Zip);
});
}
});
});
This is the code in my controller;
public JsonResult DropDownChange(string dropdownValue)
// This action method gets called via an ajax request
{
if (dropdownValue != null && Request.IsAjaxRequest() == true)
{
paymentApplicationRefund =
cPaymentRepository.PayableEntity(dropdownValue);
paymentApplicationRefund.Address1.Trim();
paymentApplicationRefund.Address2.Trim();
paymentApplicationRefund.Name.Trim();
paymentApplicationRefund.City.Trim();
paymentApplicationRefund.Contact.Trim();
paymentApplicationRefund.State.Trim();
paymentApplicationRefund.Zip.Trim();
return Json(paymentApplicationRefund,"application/json");
}
else
{
return null;
}
}

Posted: Mar 4 at 20:48

View 3 Replies!   View Related
MVC :: Passing A List Of Objects From View To Controller Via Jquery Ajax?
I have a form that I don't want to post back so I need to get the form values into my controller via jquery's ajax method.Here is my test controller method:

[Code]....

When I debug the controller method and look at the lineItems parameter, it always contains 0 items. I've tried various formats for the javascipt lineItems parameter but still 0 items. I'm also open to some other way of getting these values in like the jquery form serialze method or something else.

Posted: Jan 22, 2010 07:37 PM

View 2 Replies!   View Related
MVC :: Pass Values From View To Controller?
I am new in MVC. I have 3 TextBox and 2 buttons (One "Sum" Other for "Mult") on Viewpage.

In the controller I have created 2 actions (1) is Sum and other is "Mult".

When User click on button 1(Sum) then value from Textbox 1 and texbox 2 should pass to the Action "Sum", this action will do sum of this two value and return result into the texbox3, like wise with other button "Mult" which does multiplication.

I dont know how to pass value / Call "Sum" Action on click of "SUM" Button.

Posted: May 15, 2009 12:51 AM

View 1 Replies!   View Related
MVC :: Paasing Textbox And Checkbox Values From View Form To A Controller?
I have a view with a form..this form has a textbox and a checkbox in it.

i also have a submit button in the form which points to an action in a controller.

my question is..how can i pass the values in the textboxes and the checked state of the checkboxes to the controller action? the textboxes and checkboxes are not tied to a model.

Posted: Jun 23, 2010 12:03 PM

View 7 Replies!   View Related
MVC :: Finding Example For Passing Values To Partial Views (and Or To View Database Pictures)
I probally just tired but I would have sworeI had seen an example of this some where for MVC 2,

I want to call apartial view that shows the products informationwith a GUID passed to the partial view.

I guess you would call it calling a sub but have that sub in a view that i can strongly wire up.

What i need is tutorials for passing a value to the partial view.

Like if i had pictures and i wanted to call a ascx that would show the picture. and have many to a page.

An example about pictures wired into a entities database would rock.....

I did try to look around on here to find some but my mind just gave out on me today....

Posted: Aug 11, 2010 12:31 AM

View 1 Replies!   View Related
MVC :: Redirect From One Controller View To Another Controller View Using Linq
How to redirect from One Controller View To another Controller View.

Posted: Jun 02, 2009 10:06 AM

View 3 Replies!   View Related
Binary Holding Boolean Values?
I have a 32 bitnumber in my DB/ DAL layer thatis used to represent some yes/no facilities about hotels. so I for example bit mightmean "has swimming pool", bit 2 might mean "reception desk" etc etc.Currently I have some code in the BLL that says if (number and 2) = 2 then .ispool = true - this is repeated for any many boolean hotel referances I have.What happens then is in the UI have then say something like if .ispool = true then display swimming pool icon.

Then it occurs to me that I am testing the value twice
1) To test the bin to bool in the BLL and create the structure
2) to test the structure to dislay the icon.

If I move the if (number and 2) = 2 to the UI I get the same result with one less if.Is there some better way or code do deal with this, maybe loop through the structure or something like that or an asp way that is more suitable to deal with binary representation of boolean's.

Posted: Jul 09, 2010 05:04 PM

View 2 Replies!   View Related
MVC :: Boolean Field In View - Can't Get Right Syntax?
How can i use a checkbox to represent a boolean bit field in an MVC View? Out of the box, it defaults to a textbox..There is no boolean datatype in SQL Server 2008 so i used a bit datatype. I guess its a custom template but i cant seem to get the syntax right.

Posted: Apr 02, 2010 12:57 AM

View 2 Replies!   View Related
MVC :: Session Vs TempData / How To Persist Values From Controller To Controller
I have a filter on my MVC web site. I display some records in a few different controller actions but when moving from one action to another I want to apply those filter values.

How can I persist values from controller to controller?

Should I use Session? TempData?

I am using Structure Map for IOC.

Maybe I could have a class that contains a Property for each Session Value that I use in my application and inject it on the controllers that need session?

Posted: May 30, 2010 12:54 AM

View 10 Replies!   View Related
MVC :: Pass Parameter From Controller To View And Back To Another Controller?
I have a simple model where aPerson has Gifts. I havea view which is a list ofGifts belonging to one Person.

My problem is with theCreate action for a new Gift. I want it to default to the PersonIDthat we are alreadyviewing the list ofGifts for. I tried simply passing the last PersonID (they are all the same)

Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.

My Gift List controller knows the PersonID I want to pass but the view doesn't.

How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?

Posted: Aug 16, 2010 02:53 PM

View 2 Replies!   View Related
Returning A JSON View In Combination With A Boolean?
What i would like to accomplish is that a partiel view contains a form. This form is posted using JQuery $.post. After a successfull post javascript picks up the result and uses JQuery's html() method to fill a container with the result.

However now I don't want to return the Partial View, but a JSON object containing that partial view and some other object (Success -> bool in this case).

I tried it with the following code:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Item item)
{
if (ModelState.IsValid)
{
try
{

[Code].....

However I don't get the HTML in this JSON object and can't use html() to show the result. I tried using this method to render the partial as Html and send that. However this fails on the RenderControl(tw) method with a: The method or operation is not implemented.

Posted: Apr 13 10 at 8:57

View 2 Replies!   View Related
DataSource Controls :: Filter SqlDataSource With Boolean Values?
I have an SqlDataSource, which is filtered by two RadioButtonLists. The markup is as follows:

[Code]....

In my code-behind I add the filterexpression when the radiobuttonlists are changed

[Code]....

My problem is that while it works fine when changing the RadioButtonListProducts the filtering works nicely, there is a problem with the RadioButtonListStatus, that filters on the Boolean column, 'Godkendt'. It works nicely if its set to 'Alle' (No filtering on that parameter) but when set to anything else, no records are shown. I suppose the problem is in the filterexpression

[Code]....

Posted: Feb 17, 2011 09:27 AM

View 1 Replies!   View Related
MVC :: Boolean Database Field And Create View Template?
created acreate view for an entity in my Linq model which had a bitfield in it but it turned out a textfield..can you give me an example of an ascx that will enable me use a checkbox for this instead of a textbox, which the create view template uses for ALL the fields.Also, how can i get the template to use html.displayfor() instead of html.textbox?

Posted: Mar 23, 2010 04:24 PM

View 5 Replies!   View Related
MVC :: Create A Partial View And A Controller That Will Feed Data Tothe View?
Can i create a partial view and a controller that will feed data tothe view, and if irender that partial ina Master page, the Data will show on whateverURL i am?

Or is there another way of showing content fromdatabase onevery page(view)?

Posted: Jan 27, 2010 07:18 PM

View 2 Replies!   View Related
MVC :: Passing Value From Jscript To Controller?
[Code]....

when the controller method gets called the 'loc' variable is always null, can anyone tell me the right way ?

Posted: Jul 15, 2009 12:07 AM

View 2 Replies!   View Related
MVC :: File Not Passing To Controller?
I am getting an nullreferance on file,what am I doing wrong.

<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
<%: Html.ValidationSummary(true) %>
<%: Html.Label("height") %>
<%: Html.TextBox("height") %>
<%: Html.Label("width") %>
<%: Html.TextBox("width") %>
<%: Html.Label("Media") %>
<input type="file" id="Media" name="Media" />
<input type="submit" name="btnAdd" value="Add" />
<% Html.EndForm(); %>

controller code:

[HttpPost]
public ActionResult AddMedia(Guid id, HttpPostedFileBase file, FormCollection collection)
{
string mimeType = file.ContentType; // Null Exception here ....

Posted: Aug 23, 2010 04:01 PM

View 2 Replies!   View Related
Forms Data Controls :: Changing Row Color In Grid View Based On A Boolean Field Using Rowdatabound Event
I know that variations of this same question have been posed numerous times - but I can't quite seem to find the exact solution.

I would like any row in my gridview where the boolean field "Approved" is True to be shaded gray. Here is the code that I'm using, but every row ends up being gray, regardless of the value in that "Approved" field. My guess is that I'm not correctly evaluating the boolean value in this field (which is actually a yes/no field in MS Access), Not sure if I should be reading that value as "-1", "Yes" or "True" or "NotNull"? Anyway, here is the code:

[code]....

Posted: Aug 04, 2010 04:47 PM

View 4 Replies!   View Related
MVC :: Passing Tag Id To Controller When User Click On?
When user click on <a> tag i want to pass the id value to controller

Posted: Jun 12, 2010 11:02 AM

View 1 Replies!   View Related
MVC :: Passing Value Intput Text To Controller?
i am using this code for render view

[Code]....

and this code for action Method

[Code]....

i can access the value text box by AgencyID but if i clicked onSecond record AgencyID returns first recode id totally AgencyID returns the first record id.

Posted: Mar 23, 2010 07:35 PM

View 4 Replies!   View Related
Passing Data From Usercontrol To Controller?
I am new to MVC, and trying something and got stuck somewhere in between.I have a user control there I have three textbox html type(ID, Lastname, firstname) and a submit buttom. I set the button like

<input type="button" value="Search"
onclick="location.href='<%= Url.Action("action", "controller") %>'" />

I have called this usercontrol on some view through

<%= Html.Partial("ucName") %>

Now on pressing that button(on user control) I need to pass the data from these textboxes to controller again to some specific action(Http Post action). By using this data I want to do some database interaction and storing the result in a dataset and pass this data set to same view again to show up in some Grid.I know the first part in conventional Asp.net can be done by raising the event through delegate but don't know how to do that in MVC.

Posted: Jun 1 10 at 4:41

View 2 Replies!   View Related
Web Forms :: Passing Values From Parent Page To User Control And Maintaining The Values Added
I wanted to know if we can pass values from Parent page (in this case from Default.aspx page) to the user control and maintain those values on subsequent "Add/Load" of user control.

So in short, if I click the "Add" button it loads my "webusercontrol" and also I am able to pass my default.aspx dropdownlist value to this dynamically loaded user control and assign it to a "Label or Textbox" which resides in my "webusercontrol", now the problem is that the value doesn't persists! What I meant is , when I click "Add" button again the "webusercontrol" gets loaded again perfectly but now all my "Label's" in webusercontrol has the new selected value from the default.aspx dropdownlist.

So say for instance I have a Dropdownlist in Default.aspx page with Values "Apple, BlackBerry, Nokia" and initial value to be passed is "Apple", I click the "Add" button, now my "Label" inside webusercontrol has the value "Apple", perfect! Next when I click "Add" button again and select a different value to be passed this time say "BlackBerry" now I have 2 webusercontrol loaded on the page, so that means I have 2 "Labels" with different ID's, but now my first Label initially had the value "Apple" because that's what I had passed and now when I passed the value "Blackberry" both the labels of my webusercontrol has the value "BlackBerry" instead of one being "Apple" and another "BlackBerry"

Is there a way to resolve this issue? may be Dictionary List?

Posted: Mar 18, 2011 03:24 PM

View 3 Replies!   View Related
MVC :: - View - Passing Multiple Objects To The View And Selecting Data From The Lists?
I have a view which takes two objects: booking and list of reasons for canceling that booking.I have two classes: clsBooking, clsBookingCancelationReason I can read both objects in my view - no problems there. After I read the objects, I display the booking details and I generate a list of cancelation reasons in the following way:

[Code]....

The code above generates a list of cancelation reasons.How do I pick up the selected ReasonId from the list?
I need to generate a link that will contain the bookingId and the selected reason for canceling the booking.I can get the bookingId out easily since it's stored in the Model...but how do I go about the selected ReasonId?

Posted: May 17, 2010 07:41 AM

View 5 Replies!   View Related
Passing A Controller As A Parameter - Can't Get To RedirectToAction Method
My method looks like:

public static RedirectToResult(Controller controller, ...)
{
}

when I do:

controller.

I don't see RedirectToAction, how come?

I get RedirectToAction from within the controller's action, but not when I pass the controller as a parameter to another classes method.

Posted: Jun 15 10 at 14:30

View 3 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved