Dan-Robert Samoila
Dan-Robert Samoila

Reputation: 21

Incorrect usage of @ inside cshtml page

I am trying to create a button that send a POST request to my controller. My problem is that the .cshtml page does not want to render because of some problem between the two comments. I am not sure how to apply @ to the page correctly. Could you help me?

Thanks.

@if (identity.IsInRole("AdminAFM") || identity.IsInRole("ResponsabilAFM"))
{
    if (Model.ValidationMessages.Contains("VIN") == true)
    {
        <div class="form-group">
            <div class="col-xs-6">
                <a class="btn btn-lg btn-block btn-default faa-parent animated-hover" href="@Url.Action("DownloadFile", "InvoiceValidation", new { fileName = Model.FileInfoGuid })">
                    <i class="fa fa-download faa-tada"></i>&nbsp;Descarcare fisier
                </a>
            </div>

            <div class="col-xs-6">
                <a id="ValidareManuala" class="btn btn-lg btn-block btn-success animated-hover" href="@Url.Action("ValidateInvoiceManual", "InvoiceValidation", new { ValidationID = Model.InvoiceValidationID })">
                    <i class="fa fa-check"></i>&nbsp;Validare manuala
                </a>
            </div>
        </div>

        // Zone with problem
        using (Html.BeginForm("ValidateInvoiceManualWithoutRequestNumber", "InvoiceValidation", FormMethod.Post))
        {
            @Html.TextBoxFor(Model => Model.RequestName);
            <button type="submit">Setare Numar inregistrare</button>
        }
        // end of zone with problem
    }
}

I tried like this

@using (Html.BeginForm("ValidateInvoiceManualWithoutRequestNumber", "InvoiceValidation", FormMethod.Post))
{
    Html.TextBoxFor(Model => Model.RequestName);
    <button type="submit">Setare Numar inregistrare</button>
}

Version 2:

@using (Html.BeginForm("ValidateInvoiceManualWithoutRequestNumber", "InvoiceValidation", FormMethod.Post))
{
    @Html.TextBoxFor(Model => Model.RequestName);
    <button type="submit">Setare Numar inregistrare</button>
}

Version 3:

@using (@Html.BeginForm("ValidateInvoiceManualWithoutRequestNumber", "InvoiceValidation", FormMethod.Post))
{
    Html.TextBoxFor(Model => Model.RequestName);
    <button type="submit">Setare Numar inregistrare</button>
}

Version 4:

@using (@Html.BeginForm("ValidateInvoiceManualWithoutRequestNumber", "InvoiceValidation", FormMethod.Post))
{
    @Html.TextBoxFor(Model => Model.RequestName);
    <button type="submit">Setare Numar inregistrare</button>
}

My controller

[HttpPost]
public ActionResult ValidateInvoiceManualWithoutRequestNumber(InvoiceModel model) 
{
    using (var conn = new SqlConnection(connectionString))
    using (var command = new SqlCommand("ProcedureName", conn) { CommandType = CommandType.StoredProcedure }) 
    {
        conn.Open();
        command.ExecuteNonQuery();
    }

    return RedirectToAction("Index");
}

Upvotes: 1

Views: 45

Answers (1)

Serge
Serge

Reputation: 43959

should be like this , you missed a couple of @

@if (identity.IsInRole("AdminAFM") || identity.IsInRole("ResponsabilAFM"))
{
    @if (@Model.ValidationMessages.Contains("VIN") == true)
    {
     .....  
         @using (Html.BeginForm("ValidateInvoiceManualWithoutRequestNumber", "InvoiceValidation", FormMethod.Post))
        {
            @Html.TextBoxFor(model => model.RequestName);
....

but I can' t see identity.IsInRole. Where is it definded? It could be the problem too

Upvotes: 1

Related Questions