MVC :: NotSupportedException - Pass Database Data From Control To View Via ViewData
Feb 7, 2011
I'm trying to pass a list of data from the column CICodeID in my database where the currently logged in users name matches the UserId.
Here is my controller: [Code]....
And here is my view: [Code]....
This is the exception I'm getting at run time:"Cannot compare elements of type 'System.Linq.IQueryable`1'. Only primitive types (such as Int32, String, and Guid) and entity types are supported."
View 6 Replies
Similar Messages:
Feb 13, 2011
I want to pass a message from the controller to a view using Viewdata. Here is my code:
public ActionResult Create(FormCollection createPage)
{
try
{
......................
ViewData["Message"] = "Success - rec added!!!!" ;
return RedirectToAction("Index");
}
catch (Exception e)
{
ViewData["Message"] = "Exception: " + e.ToString();
return RedirectToAction("Index");
}
On my View I have:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>::><%: ViewData["Message"] %><::</h2>
<h3>==><%= ViewData["Message"] %><==</h3>
<p>
This is Index.aspx page in Controller folder
</p>
</asp:Content>
I am getting result with empty ViewData["Message"]
View 4 Replies
Jun 17, 2010
if I use a Html.Hidden field in my view, when the value click to submit the form I would like to pass this data to the controller. This variable would contain int as key and string as value,
Dictionary<int, string> interestTable = new Dictionary<int, string>();
How can I specify the htmlAttribute fo this variable in my Html.Hidden code?
<% using(Html.BeginForm("Search", "SearchMembers")) { %>
<input type="hidden" name="ResearchInterests" id="researchInterests" value=""/>
<%= Html.Hidden("fullInterestsPath") %>,
View 5 Replies
Apr 27, 2010
<%#ViewData["id"] %>
<h2>MarkerDetail</h2>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$.ajax({
url:"/Marker/MarkerDetailPartial",
data:"",
success:function(result){
$("#ReplyDetails").html(result);
},
error:function(result){
}
});
});
</script>
<div id="ReplyDetails">
</div>
& i want to send Id only By this Ajax
View 1 Replies
May 3, 2010
making my first steps with asp.net mvc and I actually create a (very) small website.I have 1 controller : TasksController1 view : Tasks/Index.aspx1 Partial View : Tasks/AvailableSorting.ascx In my controller I have 2 methods :
[Code]....
In my Tasks/Index.aspx, I add my partial view (<% Html.RenderPartial("AvaliableSorting"); %>)
That sounds simple. But, It just doesn't work : the Index return a list of Task and the parial view (should) return a list of string.The index.aspx works perfectly, but the partial view doesn't get the right model ! he gets the model of the Index page (list of Task).
View 3 Replies
Oct 27, 2010
"When a partial view is instantiated, it gets its own copy of the ViewDataDictionary object that is available to the parent view. The partial view therefore has access to the data of the parent view. However, if the partial view updates the data, those updates affect only the partial view's ViewData object. The parent view's data is not changed."Is there a common way around this? For instance I have a View containing two Partial Views (User Controls) that source the same data from the Parents ViewData. The first Partial View is able to update (add/delete) certain data from the Parents View Data, however the second Partial View sources the same data but obviously isn't reflecting the changes owing to the above MSDN statement.
View 4 Replies
May 7, 2015
I have a Datalist Which is Bind with Database..Datalist Displays Image And their Image Name.. Now i Want Details of Selected Image from Database in Next View (View 2).
Also Want to know which control should i use for click event on Image??ImageButton or <a Href="">?My Code is --
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0" >
<asp:View ID="View1" runat="server">
<asp:DataList ID="DataList1" runat="server" CellPadding="2" CellSpacing="2"
Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
[CODE]
View 1 Replies
May 18, 2010
How are you going to pass a viewdata into the sitemap file?
<%= Html.ActionLink("Home", "Index", "Home", new { id = ViewData["customRouteValue"] })%>
View 1 Replies
Jul 16, 2010
I have the following code in my post action method for Edit.
JobCardService.Update(viewData.JobCard);
var js = new JavaScriptSerializer();
ViewData["Notifications"] = js.Serialize(new {NoteificationType = "Success", Message = "The installtion was successfully updated"});
return RedirectToAction("Index");
However, on the client, ViewData is null/empty, i.e. this client code
var notifications = eval("<%= ViewData["Notifications"]%>");
renders as
var notifications = eval("");
I'm sure I'm doing something small wrong.
View 1 Replies
Jun 29, 2010
I created a base Controller for the other Controllers to derrive from, and in that controller I overrode the OnActionExecuting method so that each time any Controller executes a method, I can run some code. In that code I added a value to ViewData, and in the Master View I want to either display certain items or not based on the value of the ViewData item set. The problem is, once I get to the Master View, the ViewData doesn't have anything in it. I am not sure what I'm doing wrong.
View 1 Replies
Feb 13, 2010
I like ASP.NET MVC, because I like to have direct access to my web site's structure. However there's 1 thing that I don't like.
In Ruby on Rails to send data from Controller to View is really easy:
# Get a user in controller
@user = User.first(:id => 1)
# Display him in a view
<%= @user.id %>
In ASP.NET MVC it's much harder
// Controller
User user = new User(1);
ViewData["user"] = user;
// View
<% User user = (MyNamespace.User)ViewData["user"]; %>
<%= user.Id %>
With this ViewData thing all benefits of static languages go away, and we waste time boxing/unboxing objects.
P.S. Don't tell me to use Model object, because this is also true for other variables like integer.
And another question:
I'm trying to implement a comfrtable access to data. Since I can't use LINQ to SQL as I use Postrgresql, I have to do it on my own. I'm tired of direct SQL queries, so I'm trying to implement something like this:
User user = User.Find("first_name" => "Bob");
View 4 Replies
Mar 22, 2011
is there any way i can assigned an imageurl to html img tag from database like ... something like that or i can assign image url to html img tag from code behind like imgCaravan.ImageUrl= "~/images/" + rdr["image"].ToString(); As I am using a image swapping jquery which uses html tag to display images . The issue is I am getting the image url from the database , i just cant find a way to pass the url to html tag, I can do this by using asp image control.
View 1 Replies
Oct 26, 2010
ViewData["Title"] is accessible only the current view? or it is possible to access other views also?
View 4 Replies
May 11, 2010
i need to pass multiple viewdata to a partial view from controller
View 7 Replies
Dec 28, 2010
on the controller, i am passing my string array to the view using ViewData.
[Code]....
on the view, i cated the viewdata to string array, and made a select list.
[Code]....
but if i run the website, i get this error :
[Code]....
View 5 Replies
Dec 9, 2010
I know this is gonna be easy for some of you. I have a page that I am making for a timekeep site for my organization. The site pulls the user's username. I have a table in MSSQL that has the users informaton. This table has an ID for each user. I need to get the ID to display in a text box or literal so that I can use it in a query. Once it is in the control. I will use it to make the entry into another table that records the users time.
There may be an easier way to do it. I am just starting out and do not know how to do it.
View 21 Replies
Dec 24, 2010
My way to ASP.NET MVC was not across ASP.NET Web Forms, so it's hard for me to understand how better to pass value from ASP.NET MVC controller to ASP.NET webforms script which is inside MVC View.
For example, controller action:
[Code]....
How to assign a value of myvar from a controller action to par1 variable in the View instead "stubvalue"?
View 3 Replies
Nov 22, 2013
I use image control in mypage that I bind it from database and I define that if there isn't any image in database it do Image1.visible=false
In chrome and firefox it worked correctly but in IE show like below
What should I do?
View 1 Replies
Nov 23, 2010
Im my MVC 3.0 Application, I created a helper like below;
[Code]....
And I used that helper in a linq query as below;
[Code]....
When I fire my app, it gives me the below error. LINQ to Entities does not recognize the method 'System.String GenerateURl(System.String)' method, and this method cannot be translated into a store expression. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String GenerateURl(System.String)' method, and this method cannot be translated into a store expression. Source Error:
Line 43: public Blogs GetBlog(string urlstring) {
Line 44:
Line 45: return GetAll().SingleOrDefault(x => BlogUrlGeneration.GenerateURl(x.ArticleTitle).Equals(urlstring));
Line 46: }
Line 47:
Ä°n my blog, the link will be like below; [URL] so I need to set the above urlgenerator class into lambada. How can I do that? What would it take to make that work perfectly
View 4 Replies
Jun 23, 2010
I´have this situation: I have a Master Page for all my pages.
Inside it I have a Partial Page that render the Main Menu of my site.
My question is how to pass a data from a Controller (For example AboutController) to the Menu so it can "knows" that in the "about" li, render an aditional class in it..
Normally is: <li>About</li>
But the About page: <li class="on">About</li>
I think that controllers must send this aprameter.. or not? how?
View 2 Replies
Apr 11, 2010
I have a strongly typed view for my User edit action. When I press edit all the fields in Users model is filled with values from the DB. If I enter an invalid data for a particular field say email, then the view throws an error, but after that the email field contains data pulled from the DB and not the one which i entered previously.
I will explain to you in steps if my explanation is confusing.
1.Click the edit action.
2.A page displays with all fields in my User model.
3.Email field contains : johnson@company.com (pulled from the database)
4.I try to change the email to "johnson@company1" (This is an invalid email id)
5.The form does a post back and return an error saying that email id is invalid.
6.Email field contains : johnson@company.com (pulled from the database) and not "johnson@company1"
Is there a way to convert the FormCollection to an User model and send it back to the view?
View 12 Replies
Jul 12, 2010
Can a view pass some sort of model like data to a Master page? I am using the ViewData collection, but that makes for confusion in my code. When I specify the Master in the View, can I also specify a parameter?
View 1 Replies
Oct 8, 2010
How Can I Pass data(not the part of model) to Controller from View? View Code
[Code]....
View 4 Replies
Dec 21, 2010
I am new to asp.net. I have C# MVC application and I need read data (id, name) from .mdb file (in controller) and then pass it to view.
My controller code:
OleDbConnection con = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("App_Data/data.mdb") + ";");
View 3 Replies
Jun 16, 2015
I am doing loan sysytem where you first select the amount you want to borrow and click apply. the problem im getting is i cant seem to be able to redirect the amount selected to my second view where the client fill up the form.
View 1 Replies