So I decided to make an auction house web application as my first asp.net mvc project and I cannot figure out how to pass a parameter between two views that belong to different controllers. In the first view, Details of AuctionHouseController, I have:
<a class="btn btn-default" href="@Url.Action("Create", "Auctions", new { id = Model.ItemId })">Start Auction »</a>
and a URL: http://localhost:2142/AuctionHouse/Details/123
And here is the Details method:
public ActionResult Details(int id)
{
var item = _auctionhDbc.Items.Find(id);
return View(item);
}
I want to pass the id part of the URL - the "123" to the view where the button leads - Create of AuctionsController, where I have:
<div class="form-group">
@Html.LabelFor(model => model.Item.ItemId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Item.ItemId, new { htmlAttributes = new { @class = "form-control", @Value = " " } })
@Html.ValidationMessageFor(model => model.Item.ItemId, "", new { @class = "text-danger" })
</div>
</div>
I want to place the "123" as the default value (@Value) of the Html Editor field. How can I do that?
@Value = " "code. If the value ofItem.ItemIdis123, then it will be added automatically. You need to show yourDetails(int ID)methodItem.ItemId(and what is your model in the view? Based on what you have show you needitem.Item.ItemId = id;which does not make much sense