C# - Pass Model Values As Javascript Function Parameters From Inside Mvc Html Helper Such A Html.Radio?

Jul 20, 2010

I think I need to drop in some escape characters, but I'm not quite sure where. Here is the javascript function I'm attempting to call:

function setData(associateValue, reviewDateValue) {
var associate = document.getElementById("Associate");
var reviewDate = document.getElementById("ReviewDate");
associate.value = associateValue;
reviewDate.value = reviewDateValue;

Here is the asp .net mvc line where I'm attempting to create a Radio button with a click event that calls the above function and passes data from the model as javascript parameter values.

<%= Html.RadioButton("Selected", item.Selected, new { onClick="setData('<%=item.Associate%>','<%=item.ReviewDate%>' )" } )%>

The above throws a bunch of compile issues and doesn't work. A call such as the following does call the javascript, but doesn't get the data from the model.

<%= Html.RadioButton("Selected", item.Selected, new { onClick="setData('item.Associate','item.ReviewDate' )" } )%>
<%= Html.RadioButton("Selected", item.Selected, new { onClick="setData('item.Associate','item.ReviewDate' )" } )%>
<% String functionCall = String.Format("setData('{0}','{1}')", Html.Encode(item.Associate), Html.Encode(item.ReviewDate )) ; %>
<%= Html.RadioButton("Selected", item.Selected, new { onClick=functionCall } )%>

View 2 Replies

Similar Messages:

MVC :: Getting The ID For A Model Property From HTML Helper

Jan 25, 2011

Is there a way to retrieve the client side ID for a model property similar to how the helpers like LabelFor etc generate the ID? For example, I have a model with a DateOfBirth property. I want to hook up that field to a jQuery DatePicker. Normally, I would hook up the date picker like this:


This works fine but hard codes the DateOfBirth property name. Ideally, I would like to use this:


Is this already available out of the box somewhere? I just created an extension method on the HtmlHelper class that does exactly this, but I wondered if there was already something built-in so I don't have to reinvent and test the wheel.

View 10 Replies

Web Forms :: Pass Variable As Html Control Through To Javascript Function

Jan 24, 2011

I have a function that gets the position of a control.


All the function needs is an htmlcontrol being fed to it as the parameter (elemRef). I can declare a variable in Javascript of the same content page but different function and pass the parameter successfullly getting returned values. For example, if I have the following function:

function (getPosition)
{ var txtBox1 = document.getElemendById('<%=txtBox1.ClientID %>');

I will get the coordinates of the control txtBox1. But how can I accomplish this if I am calling this function from a javascript function or codebehind of the Master Page, or codebehind of the same content Page.

View 4 Replies

Data Controls :: Pass Multiple Eval Values To JavaScript Function Inside GridView

May 7, 2015

I want to pass hidden variable to javascript from href. Below is the code used

<input runat="server" id="hidOrganizationId" type="hidden" value="" />
<ul class="gloMenu">
<li id="liOrg" runat="server">
<a href="javascript: DataEncryption('../Admin/DetailPage.aspx?OrganizationId=' + hidOrganizationId)">
<b>Ordering Facility</b>

View 1 Replies

C# - Creating Multiline Textbox Using Html.Helper Function?

Feb 16, 2011

I usually find my answers at stackoverflow but this one has bugged me for a couple of days now. I am trying to create a multiline Textbox using ASP.NET MVC with the following code.

<%= Html.TextBox("Body", null, new { TextBoxMode = "MultiLine", Columns = "55px", Rows = "10px" })%>

It just shows up a single line fixed sized textbox. on the other hand

<asp:TextBox runat="server" ID="Body" TextMode="MultiLine" Columns="55" Rows="10"></asp:TextBox>

renders the right view, but in the controller's post method with formCollection named form


returns a null value.

View 2 Replies

MVC :: Why Are HTML Helper Methods In MVC Are Inside Server Tags

Jan 9, 2010

I am new to MVC. why HTML helper methods are inside asp server tags?

for example <%=Html.Textbox("Textbox1")%>

are they equivalnet to asp.net web form server tags. Like in web forms we have

<asp:TextBox runat="server"></asp:TextBox>

If someone can kindly explain.

View 1 Replies

Jquery - Reference Form By Name In Javascript Using An BeginForm Html Helper

Apr 5, 2011

I'm sure I'm going about this wrong but I'm trying to write a simple javascript method that will set a hidden type value upon a link click. I'm using the Html.BeginForm() helper that contains two links similar to:

@Html.ActionLink("Delete Review Only", "Delete", new { id = Model.ReviewId }, new { onclick = "SetDeleteType(1);" })

<script language="JavaScript" type="text/javascript">
function SetDeleteType(selectedtype) {
document.supportform.deleteType.value = selectedtype;

The supportform name obviously doesn't exists since I'm using BeginForm() and can't specify a form name. Is there a clever way of doing this without calling Forms(0) using jQuery or something or am I completely off?

View 1 Replies

MVC: When To Use Custom HTML Helper Methods Vs Html.RenderAction

Feb 10, 2010

It's a little unclear for me on when to use a custom helper method and when to use RenderAction and also when to simply use ViewData instead. Some of their functions overlap slightly.

For example, if I were to create a Category navigation bar, would I create a new helper method and place that in some partial view? I had initially though of doing this, but I read on some blog to use RenderAction instead.

Assume the list of categories is coming from some data source.

View 4 Replies

Html Helper Html.RouteLink Possible To Place Image?

Aug 30, 2010

<%= Html.RouteLink(">>>", new { page = (Model.PageIndex + 1) },null)%>

Is it possible to set image instead ">>>" and how?

View 2 Replies

Javascript - Ajax Call Pass Parameters To Function?

Feb 7, 2011

What is wrong with this code? I am trying to pass parameters to a WCF function. I couldn't get this to work. I am getting Ajax error.

url: applicationPath + "/Test.svc/GetData",
type: "POST",
dataType: "json",
data: '{GId":' + sender.get_value() + '"GName":' + sender.get_text() + '"mId":' + testId + '}',
contentType: "application/json; charset=utf-8",
success: function(result)
//trying to fill combobox here

View 1 Replies

MVC :: Pass Multiple Parameters In Html.actionlink?

Oct 9, 2010

how can i pass multiple parameters in html.actionlink?

View 1 Replies

MVC :: Model Binding Values In HTML Table Back To Controller

Aug 25, 2010

Currently, I am working with ASP.NET MVC1 and am still learning about Model Binding and how values from a View are passed back to the Controller / Model. Specifically, I want take an existing Model, create a Table and populate the Rows of the Table, allow the user to edit some fields and pass it back. In my example, I have a Class called "Ingredient" which has 4 public accessories: Name, Barcode, Amount, and Unit.

Or is this not possible? (Basically, I'm trying to re-create a datagrid where certain fields are editable and certain are not...)

View 2 Replies

HTML "id" Attribute For Items In Dropdown Made From Html Helper

Jan 5, 2011

Can we set an id attribute as I would for something like a table column via: for an html dropdown list element that is created with a helper such as:

<% for (int i = 0; i < Model.Trx.TransactionHolidayCityCollection.Count; i++)
<%= i > 0 ? "," : "" %>
<%= DropDownData.HolidayDays().ToList().Find(item => item.Value == Model.Trx.TransactionHolidayCityCollection[i].HolidayCityID.Value.ToString()).Text %>
<%} %>

View 1 Replies

MVC :: The Name 'Html' Does Not Exist In The Current Context / Not Recongnizing The Html And Model Classes?

Apr 30, 2010

I am working on an ASP.NET MVC 2 project with VS 2010 and out of nothing I get the following errors on my views:

The name 'Html' does not exist in the current context

The name 'Model' does not exist in the current context

It is like it is not recongnizing the MVC Html and Model classes.

I have System.Web.Mvc on my references and on Web.Config I have:


View 2 Replies

MVC :: Integrate Html.CheckBoxFor And Html.LabelFor - Variable For Model?

May 20, 2010

Can I integrate Html.CheckBoxFor and Html.LabelFor to create the following:


What type of variable should I pass in the model to hold the choises?

View 6 Replies

JavaScript - Ajax Post Doesn't Work With HTML In Parameters

Sep 24, 2010

After upgrading our project to the .net 4.0 framework (from 3.5), we facing some problems with ajax calls with html in the parameters. As soon as the user enters some html in a text area the ajax call isn't executed anymore. If the user enters plain text only, there is no problem.


View 2 Replies

Changing JavaScript Function In HTML

Apr 4, 2016

I type the following code:

$.getJSON(@Url.Action("GetIPAddress","getipaddress"), function (ip) {

It's not working and when I view the source of the HTML page it looks like this.

$.getJSON(/getipaddress/GetIPAddress, function (ip) {

View 4 Replies

How To Pass JavaScript Function As A Parameter In The Route Values Of Ajax Actionlink

Apr 20, 2010

I need to pass javascript function as a parameter value to the ajax actionlink in asp.net mvc app. how can we achieve this?

View 1 Replies

State Management :: Pass Values From Html To Aspx Page?

Jan 3, 2011

i want to pass values from html to aspx page.....Html PageTextBox 1 , TextBox 2 & onClick textBoxs values Pass to aspx Page...

View 4 Replies

MVC :: How To Call Javascript Function In Html.ActionLink

Sep 16, 2010

When I edit single recored in page, I use checkbox to get a selected row not every row with an actionlink element, but it seemed I cant make this way happen through calling javascript code(function GetSelectedRow() should return an id). Could anyone have a nice idea?


View 5 Replies

Call Javascript Function In Html.actionlink In Mvc?

May 18, 2010

how to call javascript function in html.actionlink in asp.net mvc? i wan to call one method which is in java script but how to call it within html.actionlink in same page

View 1 Replies

MVC - Call Javascript Function In Html.ActionLink?

Sep 16, 2010

When I edit single recored in page, I use checkbox to get a selected row not every row with an actionlink element, but it seemed I cant make this way happen through calling javascript code (function GetSelectedRow() should return an id). Could anyone have a nice idea?

<head runat="server">
<script type="text/javascript" language="javascript">
function GetSelectedRow() {
var a = 0;
var chkBoxes = document.getElementsByName("chkSelect");
var count = chkBoxes.length;
for (var i = 0; i < count; i++) {
if (chkBoxes[i].checked == true)
a = chkBoxes[i].primaryKeyID;
return a;
<span style="width:20%">
<%: Html.ActionLink("Add", "Create")%>
<%: Html.ActionLink("Edit", "Edit", new { id = GetSelectedRow()) %>
<%: Html.ActionLink("Detial", "Details", new { id = GetSelectedRow() })%>
<%: Html.ActionLink("Delete", "Delete", new { id = GetSelectedRow()) %>
<% foreach (var item in Model) { %>
<%: Html.ActionLink("Details", "Details", new { id = item.AppCategoryID })%>
<%: Html.CheckBox("chkSelect", false, new { primaryKeyID = item.AppCategoryID })%>
<%: item.AppCategoryID %>
<%: item.AppCategoryName %>
<%: item.Description %>
<% } %>

View 2 Replies

MVC :: How To Pass A Value Form ActionResult To Html.textbox Or Html.TextBoxFor In View

Mar 18, 2010

how can i passing a value form ActionResult to html.textbox or Html.TextBoxFor in View

View 2 Replies

Html.ActionLink() Gives An Empty Link When Use It Inside Html.RenderAction()?

Feb 18, 2010

I have a Microsoft MVC project with an action "Foo" whose view ("Foo.aspx") contains the lines:

<%= Html.ActionLink("mylinktext1", "bar") %>
<%= Html.ActionLink<MyController>(x => x.Bar(), "mylinktext2") %>

When I hit this from a web browser or load it from an AJAX call, it properly returns:

<a href="/bar">mylinktext1</a>
<a href="/Bar">mylinktext2</a>

But when I call the action from another view like this:

<% Html.RenderAction<MyController>(x => x.Foo()); %>

Then the links are rendered without targets.

<a href="">mylinktext1</a>
<a href="">mylinktext2</a>

Why would this be happening, and how do I work around it?

View 1 Replies

JavaScript - Jquery Change HTML Inside UpdatePanel?

Aug 17, 2010

I've got UpdatePanel with Div

<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
<div class="pnlFind" style="display:none;">

wanna use js for showing this div


but after partial postback, I got div invisible again(right! restore DOM) How can I remember that div should be always visible after button click.

View 1 Replies

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