Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
阻止用户使用浏览器';使用MVC 3、C#和不引人注目的ajax实现向后和向前功能_C#_Asp.net Mvc 3_Browser_Navigation_Unobtrusive Ajax - Fatal编程技术网

阻止用户使用浏览器';使用MVC 3、C#和不引人注目的ajax实现向后和向前功能

阻止用户使用浏览器';使用MVC 3、C#和不引人注目的ajax实现向后和向前功能,c#,asp.net-mvc-3,browser,navigation,unobtrusive-ajax,C#,Asp.net Mvc 3,Browser,Navigation,Unobtrusive Ajax,问题:阻止用户使用浏览器的向后和向前功能 使用:MVC 3 C#Microsoft Visual Studio 2010.net framework 4.0低调的ajax 我有一个可以正常工作的MVC3应用程序,使用Html.BeginForm和friends,以一种普通的书外方式使用控制器方法,将不同的模型对象作为参数,等等。除了用户能够利用浏览器的向后和向前导航功能阻碍预期的功能流之外,一切都正常。最重要的是,在这种特殊的应用中,这是不可能的 到目前为止,我已经通过使用一个自制的FSM(有限

问题:阻止用户使用浏览器的向后和向前功能

使用:MVC 3 C#Microsoft Visual Studio 2010.net framework 4.0低调的ajax

我有一个可以正常工作的MVC3应用程序,使用Html.BeginForm和friends,以一种普通的书外方式使用控制器方法,将不同的模型对象作为参数,等等。除了用户能够利用浏览器的向后和向前导航功能阻碍预期的功能流之外,一切都正常。最重要的是,在这种特殊的应用中,这是不可能的

到目前为止,我已经通过使用一个自制的FSM(有限状态机)来“解决”这个问题,该FSM拦截尝试选择与用户状态不兼容的操作,方法是将用户发送回应用程序的开头,并显示其无法使用浏览器导航的消息。这对用户来说真的不是很友好:-)

我现在正试图使用不引人注目的ajax来解决我的问题(ajax.BeginForm)。在我尝试像使用Html.BeginForm一样来回移动模型数据之前,一切正常。我有很多关于模型和服务器端验证的现有程序代码,也使用view/viewmodel/CustomValidation,我希望将这些代码保存在可能的Ajax解决方案变体中

这一开始的scheleton非常出色(细节被剥离):

CommandDispatcher.cshtml视图:

@using (Ajax.BeginForm("CommandDispatcher", "Adm", new AjaxOptions{ UpdateTargetId = "result" }))
{
    <div id="result">
        @Html.Partial("SomeAction001") @* Only run the first time *@
    </div>
}
<input type="submit" id="SomeAction001" name="SomeAction001" value="SomeAction001" />
<input type="submit" id="SomeAction002" name="SomeAction002" value="SomeAction002" />
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult StartCommandDispatcher()
{
    return View("CommandDispatcher");
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CommandDispatcher()
{
    string action = translateToAction(Request);
    return findPartialView(action);
}

private static string translateToAction(HttpRequestBase request)
{
    string action = <find out which push button has been pressed and translate that to a known action>;
    return action;
}

private ActionResult findPartialView(string action)
{
    string partialViewName = <look up a dictionary or something>;
    ActionResult ar = PartialView(partialViewName);
    return ar;
}
@使用(Ajax.BeginForm(“CommandDispatcher”、“Adm”、新的AjaxOptions{UpdateTargetId=“result”}))
{
@Html.Partial(“SomeAction001”)@*仅第一次运行*@
}
SomeAction001.cshtml部分视图:

@using (Ajax.BeginForm("CommandDispatcher", "Adm", new AjaxOptions{ UpdateTargetId = "result" }))
{
    <div id="result">
        @Html.Partial("SomeAction001") @* Only run the first time *@
    </div>
}
<input type="submit" id="SomeAction001" name="SomeAction001" value="SomeAction001" />
<input type="submit" id="SomeAction002" name="SomeAction002" value="SomeAction002" />
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult StartCommandDispatcher()
{
    return View("CommandDispatcher");
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CommandDispatcher()
{
    string action = translateToAction(Request);
    return findPartialView(action);
}

private static string translateToAction(HttpRequestBase request)
{
    string action = <find out which push button has been pressed and translate that to a known action>;
    return action;
}

private ActionResult findPartialView(string action)
{
    string partialViewName = <look up a dictionary or something>;
    ActionResult ar = PartialView(partialViewName);
    return ar;
}

SomeAction002.cshtml部分视图:

@using (Ajax.BeginForm("CommandDispatcher", "Adm", new AjaxOptions{ UpdateTargetId = "result" }))
{
    <div id="result">
        @Html.Partial("SomeAction001") @* Only run the first time *@
    </div>
}
<input type="submit" id="SomeAction001" name="SomeAction001" value="SomeAction001" />
<input type="submit" id="SomeAction002" name="SomeAction002" value="SomeAction002" />
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult StartCommandDispatcher()
{
    return View("CommandDispatcher");
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CommandDispatcher()
{
    string action = translateToAction(Request);
    return findPartialView(action);
}

private static string translateToAction(HttpRequestBase request)
{
    string action = <find out which push button has been pressed and translate that to a known action>;
    return action;
}

private ActionResult findPartialView(string action)
{
    string partialViewName = <look up a dictionary or something>;
    ActionResult ar = PartialView(partialViewName);
    return ar;
}

控制器:

@using (Ajax.BeginForm("CommandDispatcher", "Adm", new AjaxOptions{ UpdateTargetId = "result" }))
{
    <div id="result">
        @Html.Partial("SomeAction001") @* Only run the first time *@
    </div>
}
<input type="submit" id="SomeAction001" name="SomeAction001" value="SomeAction001" />
<input type="submit" id="SomeAction002" name="SomeAction002" value="SomeAction002" />
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult StartCommandDispatcher()
{
    return View("CommandDispatcher");
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CommandDispatcher()
{
    string action = translateToAction(Request);
    return findPartialView(action);
}

private static string translateToAction(HttpRequestBase request)
{
    string action = <find out which push button has been pressed and translate that to a known action>;
    return action;
}

private ActionResult findPartialView(string action)
{
    string partialViewName = <look up a dictionary or something>;
    ActionResult ar = PartialView(partialViewName);
    return ar;
}
[AcceptVerbs(HttpVerbs.Get)]
公共操作结果StartCommandDispatcher()
{
返回视图(“CommandDispatcher”);
}
[接受动词(HttpVerbs.Post)]
公共操作结果CommandDispatcher()
{
字符串操作=translateAction(请求);
返回findPartialView(操作);
}
私有静态字符串translateAction(HttpRequestBase请求)
{
字符串动作=;
返回动作;
}
私有操作结果findPartialView(字符串操作)
{
字符串partialViewName=;
ActionResult ar=PartialView(PartialView名称);
返回ar;
}
为了让这个场景也能处理其中的数据:-),我需要添加模型呈现和验证功能

将模型发送到浏览器没有问题,例如在局部视图中添加了以下内容:
@Html.Raw((模型为MyViewModel.Field1)
,它按预期和期望的方式呈现。我认为问题在于从浏览器到控制器的方向

如何引入此类功能