how to use modal popup in my partial view in mvc





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















i want to load Modal as popup on button click through which user can save info in the database problem i am facing is my partial view which consist of that button has
IEnumerable modal and the modal form consist of normal model like @model Key so one model overlapping other and it is not working.



Here is my view



@model IEnumerable<RoomTypeView>

<div class="card border rounded DropShadow" style="border-top-right-radius:50%;">
<div class="card-body">
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.RoomNo)
@Html.DisplayFor(modelItem => item.GuestName)
@($"{item.CheckIn:dd/MMM} - {item.CheckOut:dd/MMM}")
@Html.DisplayFor(modelItem => item.Status)
<div class="form-inline">
<button type="button" class="btn btn-default modalkey" data-toggle="modal" data-target="#myModal"><i class="fas fa-key" style="@(item.Status.HasFlag(EnumHkStatus.Repair) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-broom" style="@(item.Status.HasFlag(EnumHkStatus.Cleaning) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-clipboard-list" style="@(item.Status.HasFlag(EnumHkStatus.InventoryCheck) ? "color:red;": "")"></i></button>
</div>
@Html.DisplayFor(modelItem => item.Comments)
}
</div>
</div>

@model KeyLog
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Key Log</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@if (Model?.KeyLogId > 0)
{
@Html.HiddenFor(model => model.KeyLogId)
}

<div class="form-group">
@Html.LabelFor(model => model.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.NameOfPerson, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.NameOfPerson, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.NameOfPerson, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.PurposeForGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.PurposeForGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.PurposeForGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyReturned, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyReturned, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyReturned, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>


is there another way to achieve this with placing that modal into another view










share|improve this question























  • You can't use two different models in a single view. You could approach this using a ViewModel or possibly a partial view.

    – Wubbler
    Jan 3 at 13:50











  • @Wubbler can you suggest me any article with using partial view

    – kunals
    Jan 3 at 13:58











  • @kunals There are a huge range of materials available online, Google is your friend.

    – Darkoj1
    Jan 3 at 15:21


















1















i want to load Modal as popup on button click through which user can save info in the database problem i am facing is my partial view which consist of that button has
IEnumerable modal and the modal form consist of normal model like @model Key so one model overlapping other and it is not working.



Here is my view



@model IEnumerable<RoomTypeView>

<div class="card border rounded DropShadow" style="border-top-right-radius:50%;">
<div class="card-body">
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.RoomNo)
@Html.DisplayFor(modelItem => item.GuestName)
@($"{item.CheckIn:dd/MMM} - {item.CheckOut:dd/MMM}")
@Html.DisplayFor(modelItem => item.Status)
<div class="form-inline">
<button type="button" class="btn btn-default modalkey" data-toggle="modal" data-target="#myModal"><i class="fas fa-key" style="@(item.Status.HasFlag(EnumHkStatus.Repair) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-broom" style="@(item.Status.HasFlag(EnumHkStatus.Cleaning) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-clipboard-list" style="@(item.Status.HasFlag(EnumHkStatus.InventoryCheck) ? "color:red;": "")"></i></button>
</div>
@Html.DisplayFor(modelItem => item.Comments)
}
</div>
</div>

@model KeyLog
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Key Log</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@if (Model?.KeyLogId > 0)
{
@Html.HiddenFor(model => model.KeyLogId)
}

<div class="form-group">
@Html.LabelFor(model => model.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.NameOfPerson, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.NameOfPerson, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.NameOfPerson, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.PurposeForGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.PurposeForGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.PurposeForGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyReturned, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyReturned, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyReturned, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>


is there another way to achieve this with placing that modal into another view










share|improve this question























  • You can't use two different models in a single view. You could approach this using a ViewModel or possibly a partial view.

    – Wubbler
    Jan 3 at 13:50











  • @Wubbler can you suggest me any article with using partial view

    – kunals
    Jan 3 at 13:58











  • @kunals There are a huge range of materials available online, Google is your friend.

    – Darkoj1
    Jan 3 at 15:21














1












1








1








i want to load Modal as popup on button click through which user can save info in the database problem i am facing is my partial view which consist of that button has
IEnumerable modal and the modal form consist of normal model like @model Key so one model overlapping other and it is not working.



Here is my view



@model IEnumerable<RoomTypeView>

<div class="card border rounded DropShadow" style="border-top-right-radius:50%;">
<div class="card-body">
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.RoomNo)
@Html.DisplayFor(modelItem => item.GuestName)
@($"{item.CheckIn:dd/MMM} - {item.CheckOut:dd/MMM}")
@Html.DisplayFor(modelItem => item.Status)
<div class="form-inline">
<button type="button" class="btn btn-default modalkey" data-toggle="modal" data-target="#myModal"><i class="fas fa-key" style="@(item.Status.HasFlag(EnumHkStatus.Repair) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-broom" style="@(item.Status.HasFlag(EnumHkStatus.Cleaning) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-clipboard-list" style="@(item.Status.HasFlag(EnumHkStatus.InventoryCheck) ? "color:red;": "")"></i></button>
</div>
@Html.DisplayFor(modelItem => item.Comments)
}
</div>
</div>

@model KeyLog
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Key Log</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@if (Model?.KeyLogId > 0)
{
@Html.HiddenFor(model => model.KeyLogId)
}

<div class="form-group">
@Html.LabelFor(model => model.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.NameOfPerson, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.NameOfPerson, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.NameOfPerson, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.PurposeForGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.PurposeForGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.PurposeForGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyReturned, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyReturned, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyReturned, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>


is there another way to achieve this with placing that modal into another view










share|improve this question














i want to load Modal as popup on button click through which user can save info in the database problem i am facing is my partial view which consist of that button has
IEnumerable modal and the modal form consist of normal model like @model Key so one model overlapping other and it is not working.



Here is my view



@model IEnumerable<RoomTypeView>

<div class="card border rounded DropShadow" style="border-top-right-radius:50%;">
<div class="card-body">
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.RoomNo)
@Html.DisplayFor(modelItem => item.GuestName)
@($"{item.CheckIn:dd/MMM} - {item.CheckOut:dd/MMM}")
@Html.DisplayFor(modelItem => item.Status)
<div class="form-inline">
<button type="button" class="btn btn-default modalkey" data-toggle="modal" data-target="#myModal"><i class="fas fa-key" style="@(item.Status.HasFlag(EnumHkStatus.Repair) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-broom" style="@(item.Status.HasFlag(EnumHkStatus.Cleaning) ? "color:red;": "")"></i></button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fas fa-clipboard-list" style="@(item.Status.HasFlag(EnumHkStatus.InventoryCheck) ? "color:red;": "")"></i></button>
</div>
@Html.DisplayFor(modelItem => item.Comments)
}
</div>
</div>

@model KeyLog
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Key Log</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@if (Model?.KeyLogId > 0)
{
@Html.HiddenFor(model => model.KeyLogId)
}

<div class="form-group">
@Html.LabelFor(model => model.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.NameOfPerson, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.NameOfPerson, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.NameOfPerson, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.PurposeForGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.PurposeForGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.PurposeForGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyGiven, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyGiven, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyGiven, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.DateKeyReturned, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.DateKeyReturned, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DateKeyReturned, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>


is there another way to achieve this with placing that modal into another view







javascript c# asp.net-mvc razor bootstrap-modal






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 13:29









kunalskunals

287




287













  • You can't use two different models in a single view. You could approach this using a ViewModel or possibly a partial view.

    – Wubbler
    Jan 3 at 13:50











  • @Wubbler can you suggest me any article with using partial view

    – kunals
    Jan 3 at 13:58











  • @kunals There are a huge range of materials available online, Google is your friend.

    – Darkoj1
    Jan 3 at 15:21



















  • You can't use two different models in a single view. You could approach this using a ViewModel or possibly a partial view.

    – Wubbler
    Jan 3 at 13:50











  • @Wubbler can you suggest me any article with using partial view

    – kunals
    Jan 3 at 13:58











  • @kunals There are a huge range of materials available online, Google is your friend.

    – Darkoj1
    Jan 3 at 15:21

















You can't use two different models in a single view. You could approach this using a ViewModel or possibly a partial view.

– Wubbler
Jan 3 at 13:50





You can't use two different models in a single view. You could approach this using a ViewModel or possibly a partial view.

– Wubbler
Jan 3 at 13:50













@Wubbler can you suggest me any article with using partial view

– kunals
Jan 3 at 13:58





@Wubbler can you suggest me any article with using partial view

– kunals
Jan 3 at 13:58













@kunals There are a huge range of materials available online, Google is your friend.

– Darkoj1
Jan 3 at 15:21





@kunals There are a huge range of materials available online, Google is your friend.

– Darkoj1
Jan 3 at 15:21












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023251%2fhow-to-use-modal-popup-in-my-partial-view-in-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023251%2fhow-to-use-modal-popup-in-my-partial-view-in-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith