How to pass multiple values for a single parameter [Resolved]

Posted by Chakravarthi under ASP.NET MVC on 1/22/2014 | Points: 10 | Views : 2488 | Status : [Member] | Replies : 13
i want to pass two values at a time for single parameter from view to controller and it will insert data as two rows

in view from user end

std_id = 1
std_name = xxxxx
std_class = yy
attendance_for_month = Jan attendance = 80%
attendance_for_month = Feb attendance = 85%

in database i want to insert above data as two rows like

std_id std_name std_class attendance_for_month attendance

1 xxxxx yy Jan 80
1 xxxxx yy Feb 85

How to resolve this?

Thanks & Regards

Chakravarthi


Responses

Posted by: kgovindarao523-21772 on: 1/22/2014 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Hope the Model Binders concept in MVC help you to resolve this situation

Here is the small example using model binders Prefix Property

Hope you underastand

let me know if you have any questions

Entity


public class AddressModel
{
public string Street { get; set; }
public string City { get; set; }
}


Controller

 public ActionResult Index()

{
return View();
}

[HttpPost]
public ActionResult Index([Bind(Prefix = "billing")]AddressModel b, AddressModel shipping)
{
string str = "";
str += "<b>Billing</b> " + b.Street + " , " + b.City + "<br/>";
str += "<b>Shipping</b> " + shipping.Street + " , " + shipping.City + "<br/>";
return Content(str);
}

View code

@using (Html.BeginForm("Index","YOURCONTROLLERNAME",FormMethod.Post))

{
<div>
Billing Address<br />
Street<input type="text" name="Billing.Street" value="" /><br />
City<input type="text" name="Billing.City" value="" /><br />
</div>

<div>
Shipping Address<br />
Street<input type="text" name="Shipping.Street" value="" /><br />
City<input type="text" name="Shipping.City" value="" /><br />
</div>
<input type="submit" name="submit" value="Submit" />
}


Thank you,
Govind

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chakravarthi on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down

Resolved
Dear Ajay

Follow the method described by K.Govindarao523@Gmail.Com and then write modify the View like this


In the above view instead of
Street<input type="text" name="Billing.Street" value="" />

use this code

@Html.LabelFor(model => model.Street, "Billing Street")
@Html.EditorFor(model => model.Street, null, "Billing.Street")

@Html.LabelFor(model => model.Street, "Shipping Street")
@Html.EditorFor(model => model.Street, null, "Shipping.Street")



Hope this helps you

Regards

Chakravarthi

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 1/22/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Did the above solution solve your problem.
Revert back if any issues
Please mark as answer if satisfied

Thank you,
Govind

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajaykumar.Pusarla on: 1/23/2014 [Member] Starter | Points: 25

Up
0
Down
if we are using same as with html helpers how can we do and i would like to know one more thing when we are using html helpers how can we write javascript using model binders.

please see below view in this i used model binders with html helpers here how can i use same model property for multiple values
ex: i would like to store one value like current year value in model.DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties and previous year value in model.DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties how can i write and how can i use it

thanks in Advance


@model Taxonomy_MVC.Models.RevenueModel

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<fieldset>
<legend>RevenueModel</legend>

<div class="editor-label">

@Html.LabelFor(model => model.DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties)
@Html.ValidationMessageFor(model => model.DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.DisclosureOfRevenueExplanatoryTextBlock)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DisclosureOfRevenueExplanatoryTextBlock)
@Html.ValidationMessageFor(model => model.DisclosureOfRevenueExplanatoryTextBlock)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.DescriptionOfAccountingPolicyForRecognitionOfRevenue)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DescriptionOfAccountingPolicyForRecognitionOfRevenue)
@Html.ValidationMessageFor(model => model.DescriptionOfAccountingPolicyForRecognitionOfRevenue)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.ShareRevenueFromOperationsJointVentures)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ShareRevenueFromOperationsJointVentures)
@Html.ValidationMessageFor(model => model.ShareRevenueFromOperationsJointVentures)
</div>

<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}


Model:

public class RevenueModel
{
[Display(Name = "Description of circumstances in which revenue recognition has been postponed pending resolution of significant uncertainties")]
public string DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties { get; set; }

[Display(Name = "Disclosure of revenue explanatory [Text Block]")]
public string DisclosureOfRevenueExplanatoryTextBlock { get; set; }
[Display(Name = "Description of accounting policy for recognition of revenue")]
public string DescriptionOfAccountingPolicyForRecognitionOfRevenue { get; set; }
[Display(Name = "Share revenue from operations joint ventures")]
public string ShareRevenueFromOperationsJointVentures { get; set; }
}


Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravan661 on: 1/24/2014 [Member] Bronze | Points: 25

Up
0
Down
hi @Ajaykumar.Pusarla

can u pleaae make your question more specific (clear)
As posted by govind above model binders prefix property works fine

for instance please do example same as in pasted and look how controller behaves.

Hope this helps you







sravan

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajaykumar.Pusarla on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
Please find the image in that last textboxes "TAG2277 Share revenue from operations joint ventures"
here two text boxes are there one for current year and another for previous year
i have model like:


public class RevenueModel

{
[Display(Name = "Description of circumstances in which revenue recognition has been postponed pending resolution of significant uncertainties")]
public string DescriptionOfCircumstancesInWhichRevenueRecognitionHasBeenPostponedPendingResolutionOfSignificantUncertainties { get; set; }

[Display(Name = "Disclosure of revenue explanatory [Text Block]")]
public string DisclosureOfRevenueExplanatoryTextBlock { get; set; }
[Display(Name = "Description of accounting policy for recognition of revenue")]
public string DescriptionOfAccountingPolicyForRecognitionOfRevenue { get; set; }
[Display(Name = "Share revenue from operations joint ventures")]
public string ShareRevenueFromOperationsJointVentures { get; set; }

}


i designed view like
<div class="editor-label">

@Html.LabelFor(model => model.ShareRevenueFromOperationsJointVentures)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ShareRevenueFromOperationsJointVentures)
@Html.ValidationMessageFor(model => model.ShareRevenueFromOperationsJointVentures)
</div>


but i designed for one textbox with @Html.EditorFor(model => model.ShareRevenueFromOperationsJointVentures) , how can i design one more textbox with same model property like image in attachment
 Download source file

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajaykumar.Pusarla on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
Thank you chakravarthi,

i know one more thing how we use shipping.street in javascript code, suppose at the time of lost focus of shipping.street textbox, i would like to sum the shipping.street value with 10 and assign to another textbox how we write

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 1/24/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Specify the id attribute to your text box and
work with that id in java-script.

<input type="text" id="txtBillingStreetAddress" name="Billing.Street" value="" />


JQuery Code
$(document).ready(function(){
$("#txtBillingStreetAddress").blur(function(){
// Do your manipulations here
});
});


Thank you,
Govind

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajaykumar.Pusarla on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
@Html.LabelFor(model => model.Street, "Billing Street")

@Html.EditorFor(model => model.Street, null, "Billing.Street")



@Html.LabelFor(model => model.Street, "Shipping Street")

@Html.EditorFor(model => model.Street, null, "Shipping.Street")


using above code how can we do the javascript and how javascript knows it's shipping.street or billing.street

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chakravarthi on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
Dear Ajay,

Default Id for object in EditorFor is object name like for model.Street Id is Street and
if there is any HtmlFieldName included then the Id will be prefix_model object like in the above code we defined HtmlFildName as Billing.Street here Billing is prefix so The Id will be Billing_Street

 


JQuery Code :
<script type = "text/javascript">
$(document).ready(function(){
$("#Billing_Street").blur(function(){ // Do your manipulations here
});
$("#Shipping_Street").click(function () { alert("modified");});
});
</script>


Regards

Chakravarthi

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 1/24/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Using EditorFor syntax, The Id for shipping street is Shipping_Street
Javascript code:
 <script src="../../jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#Shipping_Street").blur(function () {
$(this).val(10);
});
$("#Billing_Street").blur(function () {
alert('Hi');
});
});
</script>

cshtml code:

@Html.EditorFor(model => model.Street, null, "Billing.Street")
@Html.LabelFor(model => model.Street, "Shipping Street")
@Html.EditorFor(model => model.Street, null, "Shipping.Street")




Thank you,
Govind

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 1/27/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi Ajaykumar.Pusarla,

Did you got the solution to your requirement,
if not, revert back with issues,else you did, Please mark as answer.

Thank you,
Govind

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Snaveen on: 2/13/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

That's depend upon your table structure. If your table accepted to insert data based on id and month wise then there is no issue to insert.

Better to include both id and month as in relationship. And you just insert the data as usual..

Chakravarthi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response