MVC :: Setting Default Values In A Viewmodel?
Jun 17, 2010
i am creating inintalizing a viewmodel with the following code in an create action;
[Code]....
the class applications is a LINQ to SQL Class and it has a property called VacancyID.
I want to default this VacancyID to '3'. From within this Action..
View 2 Replies
Similar Messages:
Apr 15, 2010
I am trying to build a web user control and set some default values for its properties in the code-behind like this:
[DefaultValue(typeof(int), "50")]
public int Height { get; set; }
[DefaultValue(typeof(string), "string.Empty")]
public string FamilyName { get; set; }
[DefaultValue(typeof(Color), "Orange")]
public System.Drawing.Color ForeColor { get; set; }
When I add the user control to the page and call it without any properties:
<uc1:Usercontrol ID="uc" runat="server" />
the default values are not set and every property is 0 or null.
View 2 Replies
Jan 31, 2011
I have a gridview which I use to add items through the footer and the EmptyDataTemplate. There is a date field. I want to set the default of it to the current system date.
gridview template code is as follows...
[Code]....
Empty data template code is as follows...
[Code]....
View 4 Replies
Jan 8, 2011
Prior to using a ViewModel, I could easily pass the "soon to be edited" object directly to the view without needing to fuss over setting individual properties etc as the View conveniently accepted the Employee type directly..
[HttpGet]
public ActionResult EditEmployee(int? id)
{
EmployeeRepository ER = new EmployeeRepository();
Employee SomeEmployee = ER.GetEmployee(id.Value);
if(SomeEmployee!=null)
return View(SomeEmployee);
But now I'm using a ViewModel with DataAnnotations attributes applied over the top of various properties for validation purposes. Which creates a problem.. After fetching the "soon to be edited" object from the db, setting the ViewModel's values is suddenly a whole lot more complicated. I can't simply pass the retrieved object straight to the view, as the View now expects the VMEmployee type instead. I would like to be able to do something like:
[HttpGet]
public ActionResult EditEmployee(int? id)
{
EmployeeRepository ER = new EmployeeRepository();
Employee SomeEmployee = ER.GetEmployee(id.Value);
if(SomeEmployee!=null)
return View(new VMEmployee(SomeEmployee));
All paths seem to lead to a huge constructor which manually sets the values of each individual property. But I never had to do that before when I wasn't using a ViewModel. Model binding was a blessing! My objects also have complex child objects, which my form is also collecting values for, so this would be a huge/verbose task against DRY principals. I don't even really want to use a ViewModel, but am forced to because I need two different DataAnnotations rule sets for different validation scenarios applied to the same object.
All I want to do is be able to have two different DataAnnotations rule sets for different scenarios. I.e. public-facing www site vs internal-facing admin site. DataAnnotations doesn't seem to be flexible enough to easily cater for this common need. I've tried AutoMapper, but it throws an error saying it can't map my object types, I suspect because Employee was auto-generated by LINQ to SQL. What is the most elegant way to achieve this while sticking to DRY principals?
View 1 Replies
Sep 3, 2010
I am just getting started with MVC after many years of WebForms development.
I have a very simple page with two textbox fields, one called Input where a user will enter something, and one called Output where I want to return some string after they post the form, much like a postback scenario in WebForms. I have the View connected to a ViewModel for strong typing.
The ViewModel:
[Code]....
The View:
[Code]....
The Controller:
[Code]....
The problem I have is that the output text "Here is some response" never gets displayed, even though I modify the value in the HttpPost method and return the viewmodel to the view. Unless (just tried it) I set the textarea to disabled with:
[Code]....
Can someone explain this behavior? It seems as some "magic" assumes that whatever was in the input fields before the HttpPost should also be there after the post, similar to what ViewState does in WebForms.
View 2 Replies
Feb 24, 2011
Is there a way of setting the default unchecked value of a checkbox? Am not using a databound control. This is passing data from a form and would like it to pass false as opposed to null when unchecked.
View 2 Replies
Jan 28, 2010
i have a country dropdownlist (asp.net server side control) where in i wish to set United States as first country from list of alphabetical countries in drop down. How should i do that?
Plus on selection of country the respective state gets fired up. So if USA is selected in country by default, the states need to be selected by default (Of USA of course!!!)
Below is the code of country dropdown.
[Code]....
View 7 Replies
Dec 3, 2010
I am creating new website on visual studio 2008 , i am facing following viewing problem.
1. on Default.aspx code,when i am going to drug and drop a table follwing code sample is auto generate, spaces is replaced by dots but these dots does not effect or display run time i think visual studio default setting is changed. but i had tried to set default setting but no effect so how can i solve it
<table>
..............<tr>
..............<td> [code]...
View 4 Replies
Oct 27, 2010
My login.aspx is in a Login folder of my website. I want this to be the default document of my website in IIS. is this possible? or should I create a home.aspx page that redirects to login.aspx?
View 4 Replies
Mar 12, 2010
Below is a line I have in my ItemTemplate of a FormView. The value in the table is null rather than true/false. Is there any way I can set the default for this to be false if it is null? Or can I do this in my stored procedure in the Select statement to return false if null?
Code:
<asp:CheckBox ID="chkCharges" runat="server" Checked='<%# Bind("MCOverrideCharges") %>'
Text="Yes" Enabled = "False" />
View 2 Replies
Feb 27, 2011
Is there any way to set default setting to the printer through the code , so that i can imagine union and one layout for all users.
View 1 Replies
Mar 7, 2010
After a new user first registers at the website, I want to force them to first be approved by an admin before allowing them access to the full site. I created different roles in the ASP.net configuration tool that denies them access but the default setting allows them in. How do I go about this?
View 1 Replies
Jan 10, 2010
I'm binding data to my dropdown as follows:
[Code]....
So my dropdown will be populated with a list of years that could be different depending on the SchoolID passed in. I want my default value to be the max returned in the SELECT query minus 5 (so in other words, the max index minus 5). For example, if my list of years was:
2004-05
2005-06
2006-07
2007-08
2008-09
2009-10
2010-11
2011-12
2012-13
2013-14
2014-15
Dim conn As String = ConfigurationManager.ConnectionStrings("Elevation-TestConnectionString").ConnectionString
View 5 Replies
Jun 8, 2010
I have a web form that has 2 hidden fields , Formname & CreateDate ( essentialy a timestamp).
How do i populate them with values?
The formname is always the same & the createdate would be the current date & time.
View 9 Replies
Feb 14, 2011
I have two login control in the index page of my website,each of two different usertypes. there are two user types brands and creatives.the branded user will log in to brands bin(brandsbin.aspx) the Creative user will sign in to creativebin(creativebin.aspx) i am using forms authentication for signin. so i am confused here to to rediret to default path for each user types. how to set default page for each user types. in the web config file i have added like this
<authentication mode="Forms">
<forms name="forms" loginUrl="Index.aspx" defaultUrl="brandsbin.aspx" path="/" timeout="15" slidingExpiration="true"></forms>
</authentication>
View 1 Replies
Dec 8, 2010
I have one popup calandar text box (Ajax,asp.net). When i click the calendar button , it has to show the today's date in text box by default.
View 1 Replies
Oct 20, 2010
Some while ago I found a web page explaining the default size of a session was 2048 kb, the minimum was 1 kb.How can this be adjusted? And if some one has links regarding the subject I would be a happy camper :)
View 2 Replies
Apr 30, 2010
I have a page with user controls getting dynamically added. Inside some of these user controls there are form elements, either simple <input> tags or complex third party controls (Telerik RadDatePicker for example) (technical details at end).
These controls are currently being identified as part of the same form based on a ValidationGroup string setting. My question is how can I get these form elements to submit on Enter together and raise the right postback event?
I cannot use the DefaultButton panel property because I don't have the id of the submit button available within the controls server-side. I think I might be able to use jquery clientside like this:
<input onKeyPress="javascript:if (event.keyCode == 13) {$(this).change(); $('#submitclientid').click();}" ...>
But I don't know how to do that for the third party controls.
Further technical details: Each form element is in a separate DNN module. Inter-module communication can be used to pass around data server side which results in multiple modules working together as part of a single logical form on a page.
View 2 Replies
Jul 29, 2010
I am not trying to achieve anythign fancy but just trying to set default selected value for one of the dropdown that I am using. for that I am doing Items>selected= true for whatever item I want selected when i load the page. In my case, it is a month dropdows and I am selecting date 14 as selected default value out of all 30 values but somehow, out of the blue .NEt decides to show me 29 instead of 14. I am not sure if there is some another setting that is overwritting this value.
View 2 Replies
Jul 6, 2010
I'm trying to set the default button to my master page for logging in.
Basically I've got a master page, with a LoginView in it, with a Login control in it, With a button in it... When you press "Enter" I want it to use that as the default button.
(structure in sudo-code if it helps)
BODY
Form ID=Form1
LoginView ID=MasterLoginView
AnonymousTemplate
Login ID=MainLogin
LayoutTemplate
Button ID=LoginButton
I know I've got to use .FindControl("") but as much as I mess with it I can't seem to get it to hook to the button.
View 10 Replies
Jul 7, 2010
to have back fired on me a bit (See http://www.vbforums.com/showthread.php?t=620703). I have some other buttons on the page that I attach javascript to, e.g.:
btnPick12.Attributes.Add("onClick", "return Pick12();")
And in the page Head I have the script
Code:
<script type="text/javascript">
function Pick12() {
var PopupWindow = null;
[code]....
Basically I use javascript to pop open a window with a datepicker which they use to populate a textbox on the main page with a date. However, if I set a defaultbutton, when i click one of these buttons the popup window flashes to the front of the screen and then the main browser window gets focus over it. Without default button the popup stays on top.
View 4 Replies
Feb 6, 2011
I would like to set a default date, not the current date ( say 31/11/2011) for the calender control. What date format should I be using for the datetime variable so the calender control accepts the date. I have tried using the following date format but I keep getting the error: String was not recognized as a valid DateTime.
[Code]....
Or is there another way to set a date for the calender control.
View 2 Replies
Oct 21, 2010
I am trying to find a way of setting a default image(e.g. file path) for the FileUpload control so that a default image can be used if a user did NOT choose to upload an image.
View 4 Replies
Mar 20, 2010
how to set default button for a asp:Content.
I tried using the panel , but it is not working.
In one of my content page , i have two divs - div1,div2.
On page load , only the div1 will be visible. On clicking a button inside it the div1 is made to invisible and the second div- div2 is made visible.
At the page load , i want to make the button inside the div1 to be the default one. On its click i want to make the button inside the div2 to be the default one .How can i do that?
View 4 Replies
Apr 9, 2010
I want to know if there is a way to set up the default document or default web page from the setup project of a web page.What I mean is that I would like my web app installer to set the default page (i.e: DefaultPage.aspx) when installing the web application. I remember I could do this in previous versions of the asp.net platform, currently I am working in ASP.NET 3.5 (Visual Studio 2008).
View 2 Replies