How to send id of a model property Name to Controller class in an MVC4 application
public class{
public Name{get;set;}
}
For Accesing name using id of that property
Update:
Here if change Name using jquery at runtime i want to send the changed name id to the controller class
UPDate:
This is my VIew
<script type="text/javascript">
$(function () {
$('.editor input').blur(function () {
$(this).hide();
$(this).closest('p').find('label').html($(this).val()).show();
});
$('.editor label').click(function () {
$(this).hide();
$(this).closest('p').find('input').show();
});
});
@using (Html.BeginForm("Homepage", "Home", FormMethod.Post))
{
<div class="editor">
<p>
@Html.LabelFor(x => x.Name, Model.Name)
@Html.EditorFor(x => x.Name)
<input type="submit" value="OK" />
</p>
<p>
@Html.LabelFor(x => x.Company, Model.Company)
@Html.EditorFor(x => x.Company)
<input type="submit" value="OK" />
</p>
<p>
@Html.LabelFor(x => x.City, Model.City)
@Html.EditorFor(x => x.City)
<input type="submit" value="OK" />
</p>
</div>
<input type="submit" value="OK" />
}
This is my model
public class Details
{
public string Name
{ get; set; }
public string Company
{ get; set; }
public string City
{ get; set; }
}
This is my COntroller methods
public ActionResult Homepage(Details d)
{
d.Name = "Rakesh";
d.Company = "TCS";
d.City = "DElhi";
return View(d);
}
[HttpPost, ActionName("Homepage")]
public ActionResult Indexof(Details d)
{
return View(d);
}
Here i am editing and sending data to the controller but my problem is when i click on Rakesh for example and change the name then i need to click button twice then only the changed data is sent to the controller class
Model:
Controller:
If this isn’t what you need, please clarify what’s this “id” you’re talking about.