gpt4 book ai didi

c# - MVC4 和 jquery : Redirecting to another view using button and also sending parameter object (to another view)

转载 作者:行者123 更新时间:2023-12-01 07:58:28 26 4
gpt4 key购买 nike

首先,我必须说我是 MVC4 的新手,并且同时学习和开发这个应用程序。在此应用程序中有“index.cshtml” View ,它包含“fresh”span(按钮)。 单击此按钮后,我想要:

  1. 重定向到另一个名为“Interview”的 View ,
  2. 还想将参数“data”发送到 View ( Controller 操作方法)

Index.cshtml查看代码片段:

.
.
some code
<span class="action-class" id="fresh">Start Fresh Interview</span>
.
.
some code
.
.
$("#fresh").click(function (e) {
var tech;
var guid = '@Model.currentInterviewDetails.GuId';
$.ajax(
{
type: "post",
url: '@Url.Action("Interview","Home")',

data: {
GuId: guid,
IntervieweeName: $("#IntervieweName").val(),
LevelId: $("#SelectedLevelId").val(),
DId: $("#SelectedDesignationId").val(),
TrackId: $("#SelectedTrackId").val(),
TechId: tech
},

success: function (data) {

}
});
});

但是新 View (即 Interview.cshtml)未加载,我可以看到旧 View (index.cshtml)

Interview.cshtml 代码片段:

@model InterviewAssistant.Models.CommonWrapper
@{
ViewBag.Title = "Interview";
}
@
@if (Model.tech != null && Model.tech.Count() > 0)
{
@Html.HiddenFor(m => m.SelectedTrackId)
@Html.DropDownListFor(
m => m.SelectedTechId,
new SelectList(Model.tech, "TechId", "TechName"),
string.Empty
)
}

以下是 Controller 代码:

public ActionResult Interview(InterviewDetailsModel interview)
{

string name = System.Web.HttpContext.Current.User.Identity.Name;

CommonWrapper wrapper = new CommonWrapper();
wrapper.track = CommonWrapper.GetTracks();
wrapper.level = CommonWrapper.GetLevel();
wrapper.designation = CommonWrapper.GetDesignation();
wrapper.currentInterviewDetails = interview;

wrapper.tech = (from s in CommonWrapper.GetTechnology()
where s.TrackId == interview.TrackId
orderby s.TechName
select s).ToList();


return View("Interview", wrapper);

}

有人可以帮我解决这个问题吗?

提前致谢:-)

最佳答案

以简单的方式,您可以制作 Controller

 public class DefaultController : Controller
{
Public ActionResult Index()
{
Model model = new Model();
model.TechId = "TechId here";
model.TechName = "TechName";

return View(model);
}

public ActionResult InterView()
{
return View();
}

[HttpPost]
public ActionResult InterView(Model model)
{
//retrive model here

//return your interview view here
return View("InterView");
}
}

在 Index.cshtml 中查看:

@model namespace.model.modelname 

@using (Html.BeginForm("InterView", "Default", FormMethod.Post))
{
<input type="submit" name="SubmitInterview" value="Submit" />
}

关于c# - MVC4 和 jquery : Redirecting to another view using button and also sending parameter object (to another view),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21777064/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com