Guys I can't seem to figure out this one. I am kinda new to MVC and Razor so be gentle :D
I got this partial view:
@model Phonebook.PresentationLayer.Web.Models.EmailModel
@using Phonebook.BusinessLogicLayer.Managers;
@using (Html.BeginForm("AddEmail", "EmailDetails", FormMethod.Post))
{
@Model.ParseIds= Model.Id + "/" + Model.Contact.Id;
@Html.HiddenFor(x => Model.ParseIds)
<div class="info-table add-email">
<div>
@Html.EditorFor(x => x.EmailAddress, new { htmlAttributes = new { @class = "no-borders" } })
@Html.ValidationMessageFor(x => x.EmailAddress)
</div>
<div>
@{
EmailTypes emailTypesManager = new EmailTypes();
IEnumerable<EmailTypeModel> emailTypes = emailTypesManager.GetAll().Select(x => (EmailTypeModel)x);
}
@Html.DropDownListFor(x => x.EmailType.Id, new SelectList(emailTypes, "Id", "Name", Model.EmailType.Id), new { @class = "no-borders-drop" })
@Html.ValidationMessageFor(x => x.EmailType.Name)
</div>
<div>
<input type="submit" value="Save" class="btn btn-success btn-xs">
</div>
</div>
<button type="button" class="btn btn-block btn-default add-email-button">Add new email</button>
}
Which I call with:
@Html.Partial("Partial/_EmailAdd", new EmailModel(){ Contact = Model.Contact})
But it keeps giving me this error which kinda does not make any sense to me:
Anyone have an idea where the problem might be?
Also since I'm new to the Razor I was wondering when do I NEED to use semicolon (";") in the View code?
Thank you!
Okay, so I wrapped the line causing the error in @{} like so:
@{
Model.ParseIds= Model.Id + "/" + Model.Contact.Id;
}
And the error changed to:
Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.
Simply by removing @ and {} leaving the line clear (since the line was already in the block of code) solved my problem.
Thank you all for helping.