Process.Start to Open an Url, Getting an Exception

Client Id for Property (ASP.Net MVC)

Put this code somewhere:

using System; 
using System.Linq.Expressions;
using System.Web.Mvc;

namespace MvcLibrary.Extensions
{
public static class HtmlExtensions
{
public static MvcHtmlString FieldIdFor<TModel, TValue>(this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression)
{
string htmlFieldName = ExpressionHelper.GetExpressionText(expression);
string inputFieldId = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName);
return MvcHtmlString.Create(inputFieldId);
}
}
}

Then in your ASPX view:

<label for="<%= Html.FieldIdFor(m => m.EmailAddress) %>">E-mail address:</label> 
<%= Html.TextBoxFor(m => m.EmailAddress) %>

You can also use this in JavaScript calls as you won't know the control's ID in advance and may need it for some JavaScript code to work against it:

<script> $.CoolJQueryFunction('<%= Html.FieldIdFor(m => m.EmailAddress) %>'); </script>

The LabelFor HTML helper method, that someone mentioned here, won't let you specify the actual text label you want to use, you have to decorate your ViewModels with attributes to set the label text, with IMHO is ugly. I'd rather that stuff appear in the actual ASPX view part itself, not on some domain/view model. Some people will disagree with me though.

Not sure of the rules for posting links to one's blog posts, but I posted a blog on this exact topic: http://www.dominicpettifer.co.uk/Blog/37/strongly-typed--label--elements-in-asp-net-mvc-2

How can I display the client ID of a model property into a view?

Unless I'm misunderstanding your question, there is an HtmlHelper that does exactly what you want: IdFor

@Html.IdFor(x => x.Address.PostCode) // Will return Address_PostCode

Although, that's for MVC4 and up. For MVC3, you will need to roll your own. See this SO.

ASP.NET MVC - send int in create view and capture it in hidden field

Create a view model for this view

public class CreateActivity
{
public int ClientId { set;get;}
public string Title { set;get;}
}

Now in your create view, accept the client id in the url, create an object of CreateActivity view model, set the ClientId property value and send that to the view.

public ActionResult Create(int id)
{
var vm = new CreateActivity { ClientId = id };
return View(vm);
}

Now in your view

@model CreateActivity
@using(Html.BeginForm())
{
@Html.TextBoxFor(s=>s.Title)
@Html.HiddenFor(s=>s.ClientId)
<input type="submit" />
}

Since ClientId is stored in as hidden form field, it will be available when you submit the form.

[HttpPost]
public ActionResult Create(CreateActivity model)
{
// check model.ClientId
// to do : Return something
}

Set ClientID in asp.net

The good news is that in VS 2010 .Net 4, you'll have complete control over Client IDs!

Still for the current versions of .Net, you can make due. I assume you need the ID for JavaScript. If so, just get the ID like so:

<script type="text/javascript">
var myTextBox = $('#<%=TextBox1.ClientID%>');
</script>

ASP.NET Form tag client id or name in c#

The form could be accessed via the Page.Form property. So to get the form client id just use:

var formId = Page.Form.ClientID;

to get the name attribute use:

var formName = Page.Form.Name;

How to Access Client_id of Calling Client in Identity Server 4 Controller

You can get the client id from the AuthorizationRequest returned from the IIdentityServerInteractionService as follows using your code snipet:

var context = await mInteraction.GetAuthorizationContextAsync(returnUrl);
_vm.AllowedRememberMe = context.ClientId != "wpf";

However, you would be better off placing this logic in your BuildLoginViewModelAsync method where the view model is constructed rather than setting the property after construction.

ASP.net over ride client ID for form elements

2 Points with this.

1) The "Override the Name" feature was introduced in ASP.Net 4.0, where for any property you can choose a hardcoded name instead of the dynamic name. You need to be careful on this as you don't want 2 objects sharing a name.

2) ASP.Net 2.0 and above (may have been in v1.0) has a property on the control called "AutoCompleteType" which provides a hint to the browser on what sort of information is required in the box.

Reference a control's ID created with TextBoxFor()

Since MVC4 there is a built-in way to do it - @Html.IdFor().

Here is a sample of using it:

@Html.IdFor(m => m.Filters.Occurred.From)

and the result is like

Filters_Occurred_From


Related Topics



Leave a reply



Submit