MVC :: Get Property / Field Value Inside Attribute

Dec 22, 2010

I want to disallow entering html tags inside specific textFields using custom attribute HtmlRemove, but I don't know how can I acces property/Field value? Model:

[Code]....

My custom Attribute

[Code]....

View 8 Replies


Similar Messages:

MVC :: Retrieve Attribute With Property Name

Sep 6, 2010

What is the best way to obtain an attribute such as the DisplayNameAttribute of a model's property using the property's name. I am using the following method currently:

[Code]....

Looking at this long statement, I cannot help wondering if there is a better way to do it.

View 4 Replies

C# - Get Property's Display Name From A Custom Attribute?

Nov 7, 2010

I am trying to create a minimum length validation attribute which will force users to enter the specified minimum amount of characters into a textbox

public sealed class MinimumLengthAttribute : ValidationAttribute
{
public int MinLength { get; set; }
public MinimumLengthAttribute(int minLength)
{
MinLength = minLength;
}
public override bool IsValid(object value)
{
if (value == null)
{
return true;
}
string valueAsString = value as string;
return (valueAsString != null && valueAsString.Length >= MinLength);
}
}

In the constructor of the MinimumLengthAttribute I would like to set the error message as follows:

ErrorMessage = "{0} must be atleast {1} characters long"

How can I get the property's display name so that I can populate the {0} placeholder?

View 1 Replies

MVC :: Setting Property On A Filter Attribute From Controller?

Feb 17, 2010

here's my situation - I've created some ActionFilterAttributes that I want to apply to a custom Controller class that my other controllers can inherit from. The problem is, I need to set a property on the attribute from the final inheriting controller. So I have something like this :

[Code]....

[Code]....

View 2 Replies

Get DisplayName Attribute From MVC2 Model's Property?

Dec 28, 2010

So, I've got an contact form in my MVC 2 application.

I'd like to programatically email all properties of my "ContactModel".

Here is what I'd like to do in psuedo-ish code:

[Code]....

In case it matters...ContactModel sets up the DisplayName attributes like this:

[DisplayName("First Name")]
public string FirstName {get; set ;}

I'd like to keep this nice and DRY by not repeating the DisplayName names.

Specifically, I'd like to enumerate over each property in my ContactModel, get its DisplayName, and get its submitted value.

View 1 Replies

MVC :: HttpRequestValidationException After Using [SkipRequestValidation] Attribute On Model Property?

Nov 12, 2010

I think I might have stumbled onto a bug in ASP.NET MVC 3 RC. When I setup my MVC2 project in a new MVC3 project, copy paste classes, code, change name spaces, etc, etc, I ran into an issue in the following, simplified for explanation purpose, scenario:

Model:

public class WineDetails
{
[SkipRequestValidation]
[Required(ErrorMessage = "Beschrijving verplicht")]
public string Description { get; set; }
}

ViewModel:

public class ViewModelCreateWine
{
public MasterData MasterData { get; set; }
public WineDetails WineDetails { get; set; }
}

ActionMethod:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateWine(ViewModelCreateWine viewModelCreateWine)
{
GetMasterDataRegions(viewModelCreateWine);
if (Request.Params.ToString().IndexOf("Save") > 0)
{
if (TryValidateModel(viewModelCreateWine.WineDetails))
{
m_wineService.CreateWine(viewModelCreateWine.WineDetails);
return RedirectToAction("index", "Admin");
}
}
return View(viewModelCreateWine);
}

The ActionMethod "CreateWine" needs to call the "CreateWine" method in the WineService so that in the end a new Wine is added to the Database. So far it looks ok. As shown in the above code the [SkipRequestValidation] is set on the "Description" property of the WineDetails model so that the user can add Rich Text to the description and HTML elements are allowed during the Request validation. This works perfectly fine until the Params collection of the Request is accessed in the code to check if the Save button is clicked. When this line of code is trying to execute the following exception is thrown:

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ViewModelCreateWine.WineDetails.Description="<p>HTML Content with...").

The same exception is thrown when I put the [ValidateInput(false)] attribute on the action method. When I comment out the "if" statement and its content there is no issue and the model validation works just fine and skips the Request Validation on the Description property as expected.

In MVC2 the above code worked fine with the [ValidateInput(false)] attribute on the action method.As I said I'm not sure if this is a bug, it very well might be my own stupidity, but I thought it would be worth to mention here. So any feedback is more than welcome.

View 2 Replies

C# - DesignOnly Attribute Does Not Hide A Property In Runtime?

Jan 17, 2010

I'm building a custom web control with a public property which I only want to be available in design time (i.e. make it unavailable in code behind). The DesignOnly attribute promises to do just that, but when I set [DesignOnly(true)] it has no noticeable effect whatsoever:

[Bindable(true)]
[Category("Appearance")]
[DefaultValue(null)]
[Localizable(false)]
[DesignOnly(true)]
public string MyProp
{
get
{
return ViewState["MyProp"] as string;
}
set
{
ViewState["MyProp"] = value;
}
}

The property still appears in code behind IntelliSense. Setting a value to it in code behind works. In these respects, the behavior is just as if the attribute had never been set. And I've cleaned and rebuilt the complete solution. Twice.

View 1 Replies

Web Forms :: ID Property Of A Control Can Only Be Set Using ID Attribute In Tag And Simple Value

Mar 19, 2013

I am using repeater control and in that i am having div in item template. Now I am setting its id using eval. I want to access this div in item databound for that i am making it runat=server. But in doing so I am getting :

"The ID property of a control can only be set using the ID attribute in the tag and a simple value."

<div id="<%# Eval("RENTER_ID") %>" style="display:none"></div>

How to achieve this functionality. One more thing i am using master page and repeater is in content page.

View 1 Replies

Custom Server Controls :: Category Attribute Of User Control Property Does Not Work Correctly In Categories Tab

Aug 19, 2010

I have a User Control (ascx) and a property which a want to display in my categories tab in Visual Studio in the category named "Styles".

[Code]....

And here is the problem: Actually I do not need a get, because I only have to set the property (write only property). But when I omit the get, the property is displayed in the "Misc" category in the categories tab in Visual Studio. Only when I code the get as well, then the property is displayed correctly in the "Styles" category in the categories tab in Visual Studio.

Does anybody know why? How can I display the category correctly only with set?

View 2 Replies

How To Get The Html Control With Attribute Inside A String

Aug 6, 2010

I have a string like these:

String data = @"<table id="_grp:CONSUMER_APPLICATION" cellpadding="0" width="660">
<tbody>
<tr>
<td>
<table id="_headerTable" class="Dark" cellspacing="0" cellpadding="0" width="660" border="0">
[code]...

View 2 Replies

How To Access A Setting In Webconfig's Appsetting Section Inside A Custom Control's Attribute

Jan 26, 2010

I have a custom control that I declare like:

<hello:someControl id="asdf" />

Now I need to access a config setting in the web.config's appsetting and give access to it to the control.

I want to pass this value using the attribute.

How can I do this?

View 1 Replies

C# - Base Page Property Show Up In @Page Attribute?

Jan 27, 2010

I have create a list of public properties in our custom page. However, when I want to assign the property on any aspx file, it does not show in intellisense and when I use it it said it is a invalid attribute of element "Page".So, 2 question.How do I make it such that it shows up in intellisense?Can I set any localize variable as a value of the property in the page directive?here is the property on my base page:

/// <summary>
/// Robot meta tag
/// </summary>

[code]...

View 1 Replies

How To Bind DetailsView Field To Function Instead Of Property

Aug 5, 2010

Is it possible to display the result of a function instead of the value of a property in a DetailsView Field?

<asp:Label ID="m_LabelPlantCode" runat="server" Text='<%# Bind("PlantCode") %>'></asp:Label>
<asp:Label ID="m_LabelPlantCode" runat="server" Text='<%# Bind("PlantCode(true)") %>'></asp:Label>

View 2 Replies

How To Make NHibernate Serialize A Given Property To A Binary Field

Sep 14, 2010

I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto mapping feature for its data access. I have encountered a scenario in which I would like NHibernate to persist some classes as binary data.

public class User
{
// This field will be persisted
public virtual byte[] PortraitData { get; set; }
// This method will get me what I'm actually interested in
public virtual Image GetPortrait()
{
return SerializationHelper.Deserialize<Image>(PortraitData);
}
}

(I leave the implementation of the SerializationHelper class to the reader's imagination. It doesn't do anything complicated, just serializes and deserializes data into byte arrays and back.)

View 2 Replies

Field Or Property With Name IXC_Vendor_Circuit_ID Was Not Found On Selected Data Source?

May 3, 2010

I am displaying a table into a gridview for which I've a SQL query written which uses IF-ELSE condition. In one of the conditions, if the condition stands TRUE then one of the coloms should be eliminated from the table. But I constantly get an error:"A field or property with the name 'IXC_Vendor_Circuit_ID' was not found on the selected data source."

View 6 Replies

Web Forms :: A Field Or Property With The Name 'usergroupname1' Was Not Found On The Selected Data Source?

Oct 1, 2010

[Code]....

View 1 Replies

Forms Data Controls :: Field Or Property Not Found On Selected Source

Jan 11, 2010

I have created a gridview at runtime. its working fine when i load the grid first time. after when i am selecting next value from ddl to load grid according to that option(selecting from dropdown list and coresponding values showing in grid) showing error that "A field or property with the name 'datafield name' was not found on the selected data source." might be i am getting this error becuze the privious value is not being cleared" can anybody help me with this problem.

View 2 Replies

Web Forms :: A Field Or Property With Name EmpID Was Not Found On Selected Data Source

Apr 9, 2012

I am using two gridviews with one datasourse. I am getting one error 

A field or property with the name 'Empid' was not found on the selected data source. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: A field or property with the name 'Empid' was not found on the selected data source. Source Error: 

My code is   

<asp:GridViewid="gridview"
runat="server" DataSourceID = "SqlDataSource1"
PageSize="30" EmptyDataText = "No Records Found" EmptyDataRowStyle-HorizontalAlign ="Center"
AllowPaging="true"

[Code]....

View 1 Replies

Web Forms :: Object Reference Is Required For Non-static Field / Method Or Property

May 7, 2015

I'm using jQuery and setInterval method in my asp.net web application.

I call the webservice every 5 seconds in order to check for DB changes. When i see a change, i want to change the photo of the linkButton that located on the master page, but i can to that due to static constrains.

An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Master.get'

my c# code is:

[WebMethod()]
public static bool checkDBChange(string userId) {
DBConnection dbConnection = new DBConnection();
if (dbConnection.isChanged(userId)) {
((Site1)Master).SetImageUrl = "~/Icons/a.ico";
}
return false;
}

The SetImageUrl is a setter in my master page that sets the new url to the linkButton. How I can implement it?

View 1 Replies

How To A Property Of A Control Inside A Template

Feb 18, 2011

I need to Bind "JobRefNo" to the query string.Below binding gives an error.what is the correct way?

<asp:LinkButton ID="MoreLinkButton" PostBackUrl="/real/Coordinator/Home.aspx?JobRefNo="'<%# Bind("JobRefNo") %>' runat="server">Go To Job...</asp:LinkButton>

Link Button is inside a DataList control.Error says "Call to Bind must be assigned to a property of a control inside a template"

View 1 Replies

How To Use The Name Of The Property That Rendering Inside Template

Apr 29, 2010

I'm reviewing new features of ASP.NET MVC 2.0. During the review i found really interesting using Templated Helpers. As they described it, the primary reason of using them is to provide common way of how some datatypes should be rendered. Now i want to use this way in my project for DateTime datatype My project was written for the MVC 1.0 so generating of editbox is looking like this:

<%= Html.TextBox("BirthDate", Model.BirthDate, new { maxlength = 10, size = 10, @class = "BirthDate-date" })%>
<script type="text/javascript">
$(document).ready(function() {
$(".BirthDate-date").datepicker({ showOn: 'button', buttonImage: '<%=Url.Content("~/images/i_calendar.gif") %>', buttonImageOnly: true });
});
</script>

Now i want to use Template Helper, so i want to have above code once i type next sentence:

<%=Html.EditorFor(f=>f.BirthDate) %>

According to the manual I create DataTime.ascx partial view inside Shared/EditorTemplates folder. I put there above code and stacked with the problem. How can i pass the name of the property that I'm rendering with template helper? As you can see from my example, i really need it, since I'm using the name of the property to specify data value and parameter name that will be send during the POST requsest. Also, I'm using it to generate class name for JS calendar building. I tried to remove my partial class for template helper and made MVC to generate its default behavior. Here what it generated for me:

<input type="text" value="04/29/2010" name="LoanApplicationDays" id="LoanApplicationDays" class="text-box single-line">

As you can see, it used the name of the property for "name" and "id" attributes. This example let me to presume that Template Helper knows about the name of the property. So, there should be some way of how to use it in custom implementation.

View 1 Replies

Forms Data Controls :: Getting Error While Binding / A Field Or Property With The Name 'CAND_NAME' Was Not Found

Feb 11, 2010

I want to bind a datarow array to datagrid, if i do so i am getting an exception saying that item was not found on selected datasource.

datatab = CType(Cache("AlldataAppli"), DataTable)
Dim rws() As DataRow
rws = datatab.Select("uid=" & UID.Text)
dg.DataSource = rws
dg.DataBind()

While binding the data i am getting the following exception.

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: A field or property with the name 'CAND_NAME' was not found on the selected data source.

This datarow array contains cand_name, i am able to retrieve it through the following line of code.

rws(0).Item("CAND_NAME")

View 3 Replies

CS0120 Error - An Object Reference Is Required For The Non-static Field, Method, Or Property?

Mar 24, 2010

I am getting a CS0120 error when trying turn a button visible after checking some variables. In plain english, If AmmohelpSession.UserActions contains AmmohelpEnums.UserAction.ArticleEdit then turn the Edit button visible. Here is my comparison:

[Code]....

In the code behind for AmmohelpSession, a public class AmmohelpSession which contains a private variable: private HashSet<UserAction> _userActions; has been stated. In that same file, there is a public function for the UserActions that does a get or set method.In the code behind for AmmohelpEnums, we are setting byte variables to specific actions. Mine would be something like:

[Code]....

Where is my error coming from ?????

View 1 Replies

C# - HTML Button's OnClick Property Inside (.cs)

Jul 2, 2010

I just wanna find out if there's a way to put my onClick event inside .cs:

<button type="submit" runat="server" id="btnLogin" class="button" onclick="btnLogin_Click();">

where Login_Click() should be inside .cs:

protected void btnLogin_Click(object sender, EventArgs e)
{
// do something
}

I will not use ASP.NET button here, and that I will not put my Login_Click() event inside .html/.aspx so I can't 'expose' my codes.

View 3 Replies

Use CommandArgument Property With LinkButton Inside Repeater?

Oct 15, 2010

The link button only sets some value as true and does nothing else. When I run the code the LinkButton's event just won't fire! In my aspx page I got this LinkButton inside of a repeater with CommandName="SetDefault", some ID, runat property. That's it. In my code, inside of myRepeater_Itemcommand(), I got this

if (e.CommandName == "SetDefault")
{
Users obj = new Users();
obj.IsDefault = true;
}

[EDIT] I resolved it myself. It was a silly mistake. "l" was missing from "SetDefault" in my aspx page.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved